N
Nischal
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
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