By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,364 Members | 1,278 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,364 IT Pros & Developers. It's quick & easy.

2.0: two dependent drop down lists

P: n/a
RAM
I need to have two drop down lists in a edited row of a data list. One drop
down list should contain Groups and the second one should contain Materials
from *selected* group.
Thus, I have written:

<asp:SqlDataSource ID="GroupsList" runat="server"
ConnectionString="..." SelectCommand="SELECT ID, Name FROM Groups" />
<asp:SqlDataSource ID="MaterialsList" runat="server"
ConnectionString="..." SelectCommand="SELECT ID, Name FROM Materials WHERE
Group = @Group" >
<SelectParameters>
<asp:FormParameter FormField="ChosenGroup" Name="Group"
Type="String" />
</SelectParameters>
</asp:SqlDataSource>
<asp:HiddenField ID="ChosenGroup" runat="server" />
<asp:DataList ID="PositionsList" runat="server"
OnEditCommand="..." OnUpdateCommand="..." OnCancelCommand="..."
OnDeleteCommand="..." >
...
<EditItemTemplate>
<tr>
<td>
<asp:DropDownList ID="GroupEdit" runat="server"
DataSourceID="GroupsList" DataTextField="Name"
DataValueField="ID"
OnSelectedIndexChanged="GroupEdit_Changed">
<asp:DropDownList ID="MaterialEdit" runat="server"
DataSourceID="MaterialsList" DataTextField="Name"
DataValueField="Number" />
<td>
...
</asp:DataList>

The problem is that GroupEdit_Changed is not called when I change group in
the drop down list during editing of a PositionsList row. In
GroupEdit_Changed I have written:

protected void GroupEdit(object sender, EventArgs e)
{
ChosenGroup.Value =
((DropDownList)PositionsList.FindControl("GroupEdi t")).SelectedValue;
}

Could you help me please? Thank you!
/RAM/
Oct 9 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
NH
make sure the first dropdown list has autopostback="true" property set.

"RAM" wrote:
I need to have two drop down lists in a edited row of a data list. One drop
down list should contain Groups and the second one should contain Materials
from *selected* group.
Thus, I have written:

<asp:SqlDataSource ID="GroupsList" runat="server"
ConnectionString="..." SelectCommand="SELECT ID, Name FROM Groups" />
<asp:SqlDataSource ID="MaterialsList" runat="server"
ConnectionString="..." SelectCommand="SELECT ID, Name FROM Materials WHERE
Group = @Group" >
<SelectParameters>
<asp:FormParameter FormField="ChosenGroup" Name="Group"
Type="String" />
</SelectParameters>
</asp:SqlDataSource>
<asp:HiddenField ID="ChosenGroup" runat="server" />
<asp:DataList ID="PositionsList" runat="server"
OnEditCommand="..." OnUpdateCommand="..." OnCancelCommand="..."
OnDeleteCommand="..." >
...
<EditItemTemplate>
<tr>
<td>
<asp:DropDownList ID="GroupEdit" runat="server"
DataSourceID="GroupsList" DataTextField="Name"
DataValueField="ID"
OnSelectedIndexChanged="GroupEdit_Changed">
<asp:DropDownList ID="MaterialEdit" runat="server"
DataSourceID="MaterialsList" DataTextField="Name"
DataValueField="Number" />
<td>
...
</asp:DataList>

The problem is that GroupEdit_Changed is not called when I change group in
the drop down list during editing of a PositionsList row. In
GroupEdit_Changed I have written:

protected void GroupEdit(object sender, EventArgs e)
{
ChosenGroup.Value =
((DropDownList)PositionsList.FindControl("GroupEdi t")).SelectedValue;
}

Could you help me please? Thank you!
/RAM/
Oct 9 '06 #2

P: n/a
I am having a similar to the one listed. I have 2 dropdowns where the
2nd one is dependent on the selection in the first.

What is the basic backend code that is needed for this type of
situation?

Oct 10 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.