Session Syntax in asp.net


default1.aspx     page

session[" username " ]=textbox1.text;

default 2.aspx  page

lable1.text="welcome to "+session["username"].tostring();

Arraylist and Genric arraylist example in c#



name space :
using System.Collections;

Array list (example program )

1)  arraylist accept any kind of data type


 ArrayList al = new ArrayList();

al.Add("aa");

al.Add("bb");

al.Add(1);

for (int i = 0; i < 3; i++)

{

Label label = new Label();

label.Text = al[i].ToString();

form1.Controls.Add(label);

}


.........................................................................................................

Generic list (example)
we can create using generic perticular data type only

name space :
using System.Collections.Generic;

List lg = new List();

lg.Add(2);

lg.Add("dd"); //// ERROR (NOT ACCEPT STRING)



for (int i = 0; i < 2; i++)

{

Label label = new Label();

label.Text = lg[i].ToString();

form1.Controls.Add(label);

}

sql server command to increment row value





sqlcommand cmd=new sqlcommand="select isnull max((id,0)+1) from tablename,con";
int id=(int) cmd.executescalar();


for example student id create from 1

next come 2,3,4,5,6.....................

Gridview Binding from database using c#




asp.net using c#,net Gridview code
data display in table format for used gridview

gridview code:::

sqldataadapter da=new  sqldataadaper("select * from table name");
dataset ds= new dataset();
da.fill(da,"tablename");
gridview1.datasourse=da.tables["tablename"];
gridview1.databind();