Datagrid BIG Problem Please Help

J

Jonathan Dixon

Can someone tell me what is wrong here i am trying to get a datagrid to
populate from a datasource via and execute reader method, the sql is fine as
i have tested it but it does not put anything in the datagrid


private void DataGrid1_SelectedIndexChanged(object sender, System.EventArgs
e)

{


casedirectory = DataGrid1.SelectedItem.Cells[1].Text;


NameValueCollection col = ConfigurationSettings.AppSettings;

String strConnection = col.Get("odbcConnection1.ConnectionString");


OdbcConnection objConnection = new OdbcConnection(strConnection);

String strSQL = "SELECT MH_ID, MH_DESCRIPTION, DIR_NAME, MH_notes, MH_DATE
FROM tblMH WHERE DIR_NAME=" + "'" + casedirectory + "'";

OdbcCommand objCommand = new OdbcCommand(strSQL, objConnection);

objConnection.Open();

OdbcDataReader objDataReader;

objDataReader = objCommand.ExecuteReader();

if (objDataReader != null)

{

DataGrid2.DataSource = objDataReader;

DataGrid2.DataBind();

objDataReader.Close();

objConnection.Close();

}
 
S

Scott M.

All your code for connecting to the database and setting the datagrid's
datasource should be in the page_load event handler, not the
selectedIndexChanged event handler.
 
J

Jonathan Dixon

The data grid stuff is in the selectedindexchanged event as i only want it
to be bound to the datasource when someone has clicked on an entry in the
previous datagrid which then calls the selected indexchanged and then should
bind the second data grid.

Is it possible to do that or not, the datagrid is binding but not showing
any data in the datagrid only the headers
 
S

Scott M.

Oh, you have 2 datagrids...You should give us ALL your code to take a look
at then.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top