Bind Date In DataGrid.

By Goniey N (Mr. G)

A Source Code For Bind Data Into Your DataGrid.

//Create This Function & Pass Two Argument...

//     1st Argument : For Which Datagrid You Want Bind Data...
//     2nd Argument : Which Table's Data You Want To Bind In Given Datagrid...

private void BindData(DataGrid DataGrid1, String TableName)
{

     OleDbConnection ocon=new OleDbConnection(ConfigurationSettings.AppSettings["<<YourConnectionString>>"]);
     OleDbCommand ocmd=new OleDbCommand();
      ocmd.CommandText="SELECT * FROM TableName";
      ocmd.Connection=ocon;
      ocmd.Connection.Open();
     OleDbDataReader odr=ocmd.ExecuteReader();
      DataGrid1.DataSource=odr;
      DataGrid1.DataBind();
      ocmd.Connection.Close();
}









//Call Function In Your Particular Event...
BindData(DataGridStudent, Student);

//Here Datagrid Is "DataGridStudent", In Which The Data Will Bind.
//Here "Student" Is Name Of The Table Of DataBase From Which All Data Will Bind In "DataGridStudent".

Bind Date In DataGrid.  (627 Views)