July 2010
M T W T F S S
« Jun    
 1234
567891011
12131415161718
19202122232425
262728293031  

Send SqlDbType.Xml to Store Procedure

SqlCommand command = new SqlCommand(”ReportMultiTruckGeneric”);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add(”@startDate”, SqlDbType.DateTime).Value = ProcessStartDate;
command.Parameters.Add(”@endDate”, SqlDbType.DateTime).Value = ProcessEndDate;

StringBuilder sb = new StringBuilder();

sb.Append(”<Trucks>”);
foreach (DataRow row in trucks.Tables[0].Rows)
{
sb.AppendFormat(”<TruckId>{0}</TruckId>”, row["ID"].ToString());
}
sb.Append(”</Trucks>”);

command.Parameters.Add(”@trucks”, SqlDbType.Xml).Value = sb.ToString();

DataSet queryResult = DBHook.SendSQLSelectRequest(command, out ex);

==store procedure=============
ALTER procedure [dbo].[ReportMultiTruckGeneric]
@startDate datetime,
@endDate datetime,
@trucks xml
as


set @trucksCopy = @trucks

select Trucks.TruckId.value(’.’, ‘int’)
from @trucksCopy.nodes(’Trucks/TruckId’) as Trucks(TruckId)

Format number in gridview

<asp:BoundField DataField=”prodPrice” HeaderText=”Price” HtmlEncode=”False” DataFormatString=”{0:f0}” />

Or in TemplateField

<asp:TemplateField HeaderText=”Price”>
<ItemTemplate>
<%#Eval(“prodPrice”,”{0:f0}”)%>
</ItemTemplate>
</asp:TemplateField>

Ex: {0:f0} is integer, {0:f1} is decimal with  1 digit

Unable to start debugging on the web server. You do not have permission to debug the application. The URL for this project is in the Internet zone.

1. In the Internet Explorer, “Tools” Menu, select “Internet Options”.

2. Switch to “Security” Tab.

3. Click on “Internet” (The Globe Icon. Its actually the default selected).

4. Click on “Custom Level” in the bottom.

5. Scroll down to find the “User Authentication” section.

6. Select “Automatic logon with current username and password”.

7. Click “Ok” twice to exit.

ref:http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vstechart/html/vsdebug.asp

ASP.NET - Working with Gridview TemplateFields

1. code behide
string ComputeSeniorityLevel(TimeSpan ts)
{
int numberOfDaysOnTheJob = ts.Days;
if (numberOfDaysOnTheJob >= 0 && numberOfDaysOnTheJob <= 1000)
return “Newbie”;
else if (numberOfDaysOnTheJob > 1000 && numberOfDaysOnTheJob <= 4000)
return “Associate”;
else if (numberOfDaysOnTheJob >= 4000 && numberOfDaysOnTheJob <= 8000)
return “One of the Regulars”;
else
return “An Ol’ Fogey”;
}

2. html

<asp:GridView ID=”GridView1″ Runat=”server”
DataSourceID=”employeeDataSource” AutoGenerateColumns=”False”
[...]

Call webservice from javascript

1.  VS 2005  – create new website with ASP.NET Ajax-Enabled Website , then create   WebService.asmx

using System;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Web.Script.Services;
/// <summary>
/// Summary description for WebService
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ScriptService]  // <== [System.Web.Script.Services.ScriptService]
public class WebService : System.Web.Services.WebService {

public WebService () {
//Uncomment the following line if using designed components
//InitializeComponent();
}[WebMethod]

public string HelloWorld() [...]

How to use HtmlEncode with TemplateFields, Data Binding, and a GridView

Label ID=”LabelDescription”
           runat=”server”
           Text=’<%# System.Web.HttpUtility.HtmlEncode((string)Eval(”Description”)) %>’

Asp.net Permalinks Using URL Rewriting

A Permalink is a permanent link which points to a particular blog entry or forum entry. For example the permalink for this blog article is http://csharp-codesamples.com/2009/03/aspnet-permalinks-using-url-rewriting.

This does not mean that a physical page is created for each blog entry. Instead a single page shows the data for multiple blogs articles dynamically based on some query [...]

FileUpload in UpdatePanel, ASP.NET, like Gmail

http://geekswithblogs.net/ranganh/archive/2009/10/01/fileupload-in-updatepanel-asp.net-like-gmail.aspx

ASP.NET Dynamic Data Preview #7: How Do I Use a DynamicControl in ListView and DetailsView Controls?

This video compares the same application written twice, once with Dynamic Data and once without. In the process, you add DynamicControl objects to ListView and DetailsView controls.

http://msdn.microsoft.com/en-us/library/system.web.dynamicdata.dynamiccontrol.aspx

http://www.bestechvideos.com/2008/06/02/asp-net-dynamic-data-how-do-i-use-a-dynamiccontrol-in-listview-and-detailsview-controls

Sorting Generic List

//Sorting List<> case Item is ListItem
//==============================================
List<ListItem> tempList = new List<ListItem>();

tempList.Insert(0, new ListItem(”————- Vehicle Reports 8″));
tempList.Insert(0, new ListItem(”————- Vehicle Reports 2″));
tempList.Insert(0, new ListItem(”————- Vehicle Reports 4″));

// sort asc
tempList.Sort(delegate(ListItem p1, ListItem p2) {
return p1.Text.CompareTo(p2.Text);
[...]