J
JDC
Hi all
I have a GridView template field with two DropDownLists in the Edit
Template.
The first DropDownList is populated with a fairly standard databinding:
<aspropDownList ID="cboSourceLimit01" runat="server"
DataSource = '<%# GetLimitValues((string)Eval("SomeField")) %>'
I then use the grid's RowDataBound event to populate the second list:
protected void GridView1_RowDataBound(object sender,
GridViewRowEventArgs e)
{
DropDownList cboLimit01 =
(DropDownList)e.Row.FindControl("cboLimit01");
if (cboLimit01 != null)
{
DropDownList cboLimit02 =
(DropDownList)e.Row.FindControl("cboLimit02");
Session["cboLimit02"] = cboLimit02;
PopulateSecondLimitCombo(cboLimit01.Text);
}
}
private void PopulateSecondLimitCombo(string limit01Value)
{
DropDownList cboLimit02 = (DropDownList)Session["cboLimit02"];
cboLimit02.Items.Clear();
DataObject db = new DataObject();
foreach (string s in db.GetSomeValues(limit01Value))
{
cboLimit02.Items.Add(s);
}
}
This works fine; when the editing row is displayed both lists have the
correct values.
However I want to use postbacks to change the contents of the second
combo based on what the user selects from the first:
protected void cboLimit01_SelectedIndexChanged(object sender, EventArgs
e)
{
PopulateSecondLimitCombo((sender as DropDownList).Text);
}
But when I choose a value from the first list, the page posts back, but
the second combo still contains its original values, i.e. it doesn't
update its contents.
Does anyone know how to solve this?
Cheers, JC
I have a GridView template field with two DropDownLists in the Edit
Template.
The first DropDownList is populated with a fairly standard databinding:
<aspropDownList ID="cboSourceLimit01" runat="server"
DataSource = '<%# GetLimitValues((string)Eval("SomeField")) %>'
I then use the grid's RowDataBound event to populate the second list:
protected void GridView1_RowDataBound(object sender,
GridViewRowEventArgs e)
{
DropDownList cboLimit01 =
(DropDownList)e.Row.FindControl("cboLimit01");
if (cboLimit01 != null)
{
DropDownList cboLimit02 =
(DropDownList)e.Row.FindControl("cboLimit02");
Session["cboLimit02"] = cboLimit02;
PopulateSecondLimitCombo(cboLimit01.Text);
}
}
private void PopulateSecondLimitCombo(string limit01Value)
{
DropDownList cboLimit02 = (DropDownList)Session["cboLimit02"];
cboLimit02.Items.Clear();
DataObject db = new DataObject();
foreach (string s in db.GetSomeValues(limit01Value))
{
cboLimit02.Items.Add(s);
}
}
This works fine; when the editing row is displayed both lists have the
correct values.
However I want to use postbacks to change the contents of the second
combo based on what the user selects from the first:
protected void cboLimit01_SelectedIndexChanged(object sender, EventArgs
e)
{
PopulateSecondLimitCombo((sender as DropDownList).Text);
}
But when I choose a value from the first list, the page posts back, but
the second combo still contains its original values, i.e. it doesn't
update its contents.
Does anyone know how to solve this?
Cheers, JC