Datagrid BIG Problem Please Help

Discussion in 'ASP .Net Datagrid Control' started by Jonathan Dixon, Jun 23, 2004.

  1. 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();

    }
     
    Jonathan Dixon, Jun 23, 2004
    #1
    1. Advertising

  2. Jonathan Dixon

    Scott M. Guest

    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.


    "Jonathan Dixon" <> wrote in message
    news:%...
    > 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();
    >
    > }
    >
    >
     
    Scott M., Jun 23, 2004
    #2
    1. Advertising

  3. 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
     
    Jonathan Dixon, Jun 24, 2004
    #3
  4. Jonathan Dixon

    Scott M. Guest

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


    "Jonathan Dixon" <> wrote in message
    news:uWseQ%...
    > 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
    >
    >
     
    Scott M., Jun 24, 2004
    #4
  5. Thanks i got it sorted !


    "Scott M." <> wrote in message
    news:...
    > Oh, you have 2 datagrids...You should give us ALL your code to take a look
    > at then.
    >
    >
    > "Jonathan Dixon" <> wrote in message
    > news:uWseQ%...
    > > 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
    > >
    > >

    >
    >
     
    Jonathan Dixon, Jul 1, 2004
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. steroche
    Replies:
    4
    Views:
    613
    =?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=
    Aug 25, 2005
  2. Shaguf
    Replies:
    0
    Views:
    522
    Shaguf
    Dec 24, 2008
  3. Shaguf
    Replies:
    0
    Views:
    480
    Shaguf
    Dec 26, 2008
  4. Shaguf
    Replies:
    0
    Views:
    258
    Shaguf
    Dec 26, 2008
  5. Shaguf
    Replies:
    0
    Views:
    236
    Shaguf
    Dec 24, 2008
Loading...

Share This Page