Category C#.Net

C Sharp Delegates and Plug-in Methods with Delegates

Category: C#.Net Comments: No comments

A delegate is declared by using the keyword delegate, otherwise it resembles a method declaration. delegate int delegateAdd (int x); Instantiation: To create a delegate instance, we need to assign a method (which has same signature as delegate) to delegate. static int Add (int x,int y) { return x+y; } .. //create delegate instance delegateAdd objAdd= new delegateAdd (Add); //short hand for above statement delegateAdd objAdd=Add;Read More

Difference between int, Int16, Int32 and Int64

Category: C#.Net Comments: No comments

int It is a primitive data type defined in C#. It is mapped to Int32 of FCL type. It is a value type and represent System.Int32 struct. It is signed and takes 32 bits. It has minimum -2147483648 and maximum +2147483647 capacity. Int16 It is a FCL type. In C#, short is mapped to Int16. It is a value type and represent System.Int16 struct. It is signed and takes 16 bits.Read More

Difference between Response.Redirect and Server.Transfer

Category: ASP.NETC#.Net Comments: No comments

Response.Redirect Response.Redirect() will send you to a new page, update the address bar and add it to the Browser History. On your browser you can click back. It redirects the request to some plain HTML pages on our server or to some other web server. It causes additional roundtrips to the server on each request. It doesn’t preserve Query String and Form Variables from the original request. It enables to see the new redirected URL where it is redirected in the browser (and be able to bookmark it if it’s necessary). Response. Redirect simply sends a message down to the (HTTP 302) browser.Read More

Use of Data Row in Data Table in Asp.net using C#

Category: ASP.NETC#.Net Comments: No comments

UserController objCont=new UserController();
DataTable   dt = new DataTable();
//bind all values in dt
dt=objCont.GetAllRecords();
DataRow[] rows = dt.Select();
foreach (DataRow dr in rows)
{
string name= dr["Name"];
}

Read More

Javascript Function in Item Template when using gridview in Asp.net

Category: ASP.NETC#.NetJAVA SCRIPT Comments: No comments

<asp:TemplateField>
<ItemStyle CssClass=”lblCenter” />
<ItemTemplate>
<asp:LinkButton ID=”lnkButton” runat=”server” OnClientClick==’<%# String.Format(“javascript:return displayDeleteWarning(\”{0}\”)”, Eval(“ClassId”).ToString()) %>’
</ItemTemplate>
</asp:TemplateField>

Read More

Add Java Script Function to gridview cells in Asp.net

Category: ASP.NETC#.NetJAVA SCRIPT Comments: No comments

//Add java script function on cells with value
protected void GridUsers_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[1].Attributes.Add(“onClick”, “JavaScript: GetOrderDetail(‘” + Convert.ToInt32(GridUsers.DataKeys[e.Row.RowIndex].Value.ToString()) + “‘)”);

}
}

Read More

Sorting in Asp.net using C# with up and down arrow image

Category: ASP.NETC#.Net Comments: No comments

.aspx Page .Cs Page if (!IsPostBack) { ViewState["SortingDirection"] = ""; }Read More

Show alternate color on mouse over in gridview using Asp.net

Category: ASP.NETC#.Net Comments: No comments

// Use Gridview Row Created Event protected void GridUsers_RowCreated(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow)Read More

Convert Generic List in Data Table in Asp.net using C#

Category: ASP.NETC#.Net Comments: No comments

Steps for conversion Step 1: //Create structure or class for hold data public struct GetUserInformation { public int UserId { get; set; } public string UserName { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public string Email { get; set; } public bool Approved { get; set; } } Step 2 : public DaRead More

Create DataTable in Asp.net at Run Time

Category: ASP.NETC#.Net Comments: No comments

Two ways to create data table 1. //Add Column in data table protected void AddColumns(ref DataTable ModyfiedTable, string[] columns) { for (int i = 0; i < columns.Length; i++) { ModyfiedTable.Columns.Add(columns[i]); } } DataTable ModyfiedTable = new DataTable("ModyfiedTable"); //define the columns string[] Columns = { "Description","Name","Email"}; //Call function to create columns AddColumns(ref ModyfiedTable, Columns); foreach (Info objInfo in myojb.data) { // create new row DataRow Request = ModyfiedTable.NewRow();Read More