Click here to Skip to main content
15,881,715 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello

i wnat to know How to bind a grid view to display data in grid
Posted

C#
// Just this much
myGridView.Datasource = myDataTable;
myGridView.DataBind();

Refer:
MSDN: GridView Overview[^]
MSDN: GridView Class[^]
 
Share this answer
 
Comments
Espen Harlinn 12-Jun-12 8:16am    
5'ed!
HI,
try like this, but change the connectionstring and query as yours.
C#
void BindGrid()
      {
          string strSQLconnection = "Data Source=SERVERNAME;Initial Catalog=DBNAME;Integrated Security=True";
          SqlConnection sqlConnection = new SqlConnection(strSQLconnection);
          SqlCommand sqlCommand = new SqlCommand("select * from TABLE", sqlConnection);
          sqlConnection.Open();

          SqlDataReader reader = sqlCommand.ExecuteReader();

          GridView1.DataSource = reader;
          GridView1.DataBind();
      }
 
Share this answer
 
Comments
Vani Kulkarni 12-Jun-12 4:19am    
Clear and crisp. My 5!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900