DataGrid and ListBox problem...

Discussion in 'ASP .Net Datagrid Control' started by Nischal, Oct 27, 2003.

  1. Nischal

    Nischal Guest

    Hello All,

    I am trying build a web form with a listbox and datagrid on it.

    1. I have a dataset into which I load an xml file using ReadXml()
    method.

    private DataSet LoadDataSet(string FileName)
    {
    DataSet ds = new DataSet();
    ds.ReadXml(FileName);
    return ds;
    }

    2. I then populate all the tablenames into the listbox

    private void LoadTableList(DataSet ds)
    {
    this.lstTables.Items.Clear();
    foreach(DataTable dt in ds.Tables)
    {
    this.lstTables.Items.Add(dt.TableName);
    }
    this.lstTables.SelectedIndex = 0;
    }

    3. In the SelectedIndexChanged event of the listbox I am trying to
    load the rows for the particular table into the datagrid

    private void LoadDataGrid(string tbName)
    {
    this.dg.DataSource = this.ds.Tables[tbName].DefaultView;
    this.dg.DataBind();
    }

    4. Here is how I am calling the above functions:

    DataSet dsMain = new DataSet();
    dsMain = LoadDataSet(Server.MapPath("Test.Config"));
    LoadTableList(dsWebConfig);
    private void lstTables_SelectedIndexChanged(object sender,
    System.EventArgs e) { LoadDataGrid(this.lstTables.SelectedItem.Text);
    }

    PROBLEM: The SelectedIndexChanged event is throwing me an exception
    saying the dataset is empty, when infact I populated the dataset. I
    did set the AutoPostBack = true. And I am using if(!IsPostBack) in my
    page_load event.

    Can someone help me where I am going wrong.

    Appreciate your time.

    Thanks
    Nischal
     
    Nischal, Oct 27, 2003
    #1
    1. Advertising

  2. May be this is what is happening.
    You change the value in the listbox and this causes a postback, in the
    pageload method you are checking for !IsPostBack and if its a postback you
    do not populate the dataset and that might be what the error states.

    Hope this helps,
    Imtiaz Hussain
     
    Imtiaz Hussain, Oct 29, 2003
    #2
    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. blenderdude
    Replies:
    0
    Views:
    1,126
    blenderdude
    Aug 3, 2003
  2. DC Gringo
    Replies:
    0
    Views:
    418
    DC Gringo
    Apr 6, 2004
  3. kent
    Replies:
    1
    Views:
    900
    Andrew de la Harpe
    May 3, 2004
  4. Simon Prince
    Replies:
    2
    Views:
    3,371
    =?Utf-8?B?TWljaGFlbCBUYXlsb3I=?=
    Oct 19, 2004
  5. DC Gringo

    click listbox and refresh another listbox

    DC Gringo, Apr 6, 2004, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    154
    DC Gringo
    Apr 6, 2004
Loading...

Share This Page