Gridview inside dropdownlist selected index change load the other control values
-
<asp:DataList ID="dlCoordinates" runat="server" RepeatColumns="2" Width="730px" OnItemDataBound="dlCoordinates_ItemDataBound"
OnItemCommand="dlCoordinates_ItemCommand">
<ItemTemplate>
<div class="left-block">
<div class="pro-title pink">
Co -ordinate
<%--<%# Eval("ProductName")%>--%>
</div>
<div class="left">
<asp:Image ID="imgCoordinates" runat="server" ImageUrl='<%# "~/Uploads/ThumbImage/"+Eval("BigImage") %>' />
<asp:HiddenField ID="hdnIdProduct" runat="server" Value='<%# Eval("IdProduct") %>' />
</div>
<div class="right">
<div class="block1">
<p>
<span id="spanCoProductDesc" runat="server">
<%# Eval("ProductDesc") %></span></p>
</div>
<div class="block1">
<h3 class="pink">
Click swatch to view colours</h3>
<div id="divCoSwatch" runat="server" class="color-box">
</div>
</div>
<div class="block1">
<h3>
Price: <span id="spanCoProductPrice" runat="server" class=&qu -
<asp:DataList ID="dlCoordinates" runat="server" RepeatColumns="2" Width="730px" OnItemDataBound="dlCoordinates_ItemDataBound"
OnItemCommand="dlCoordinates_ItemCommand">
<ItemTemplate>
<div class="left-block">
<div class="pro-title pink">
Co -ordinate
<%--<%# Eval("ProductName")%>--%>
</div>
<div class="left">
<asp:Image ID="imgCoordinates" runat="server" ImageUrl='<%# "~/Uploads/ThumbImage/"+Eval("BigImage") %>' />
<asp:HiddenField ID="hdnIdProduct" runat="server" Value='<%# Eval("IdProduct") %>' />
</div>
<div class="right">
<div class="block1">
<p>
<span id="spanCoProductDesc" runat="server">
<%# Eval("ProductDesc") %></span></p>
</div>
<div class="block1">
<h3 class="pink">
Click swatch to view colours</h3>
<div id="divCoSwatch" runat="server" class="color-box">
</div>
</div>
<div class="block1">
<h3>
Price: <span id="spanCoProductPrice" runat="server" class=&quHi, I did it using a trick: 1- I used a HiddenField as one of my Bound fields in the DataList 2- I bound my key column to the HiddenField and to the ToolTip of your first DropDownList 3- I used drp_SelectedIndexChanged handler which is event handler of the first DropDownList to fill the second DropDown. Here is my sample(the most important parts):
<asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSource1"
onselectedindexchanged="DataList1_SelectedIndexChanged" RepeatColumns="5">
<ItemTemplate>
<asp:HiddenField runat="server" ID="hiddenField" Value='<%# Eval("TableSeq") %>' />
<asp:DropDownList runat="server" ID="drp" AutoPostBack="true" ToolTip='<%# Eval("TableSeq") %>'
onselectedindexchanged="drp_SelectedIndexChanged">
<asp:ListItem Value="1">1</asp:ListItem>
<asp:ListItem Value="2">2</asp:ListItem>
</asp:DropDownList>
<br />
<asp:DropDownList ID="drp2" runat="server" Height="16px">
<asp:ListItem Value="5"></asp:ListItem>
<asp:ListItem Value="4">4</asp:ListItem>
</asp:DropDownList>
<br />
</ItemTemplate>
</asp:DataList>and here is code behind:
protected void drp_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList drop2 ;
DropDownList drp = (DropDownList)sender;
string key = drp.ToolTip;
foreach (DataListItem item in DataList1.Items)
{
if (((HiddenField)item.FindControl("hiddenField")).Value == key)
{ //found
drop2 = (DropDownList)item.FindControl("drp2");
drop2.Items.Add(new ListItem("X", "X"));
return;
}
}
}I hope it will help, Cheers.