Manually populated combo not showing values

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:

<asp:DropDownList 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
 

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

No members online now.

Forum statistics

Threads
473,992
Messages
2,570,220
Members
46,807
Latest member
ryef

Latest Threads

Top