Wednesday, 25 July 2012

Bind Grid In Asp.net Using C#


 Step 1:- Add NameSpace  

 Using System.data.sqlclint;   //Add NameSpace 

//Type Below Code On That Event Where you Want To Bind Grid For example if you want to bind grid on button click then type below code on button click

//Create Connection

SqlConnection connection123 = new SqlConnection(ConfigurationManager.ConnectionStrings["myconnectionstring"].ConnectionString);  
 //pass command
 SqlCommand sql = new SqlCommand("select * from Tabel_Name ", connection123);                                                
 connection123.Open(); // open connction
SqlDataReader r123 = sql.ExecuteReader();
 GridView123.DataSource = r123;
GridView123.DataBind();
  connection123.Close();  //close connection

No comments:

Post a Comment