你需要把你的GridView中的UpdatePanel,並做到在代碼的背後的SelectedIndexChanged事件就像我在下面的DataList都做:
<asp:DataList ID="dlstPassengers" runat="server" OnItemDataBound="dlstPassengers_ItemDataBound"
RepeatDirection="Horizontal" RepeatColumns="2" Width="100%">
<ItemTemplate>
<div class="form-linebg" style="line-height: 32px;">
<asp:DropDownList ID="ddlCountry" AutoPostBack="true" OnSelectedIndexChanged="ddlCountry_SelectedIndexChanged"
CssClass="select-3" Style="width: 145px; margin-bottom: 9px;" runat="server">
</asp:DropDownList>
<br />
<asp:DropDownList ID="ddlCity" CssClass="select-3" Style="width: 145px; margin-bottom: 10px;"
runat="server">
</asp:DropDownList>
</div>
</ItemTemplate>
</asp:DataList>
在後面的代碼:
protected void ddlCountry_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList ddlCountry = (DropDownList)sender;
DropDownList ddlCity = (DropDownList)((DropDownList)sender).Parent.FindControl("ddlCity");
BindCity(ddlCity, ddlCountry.SelectedValue);
}
private void BindCity(DropDownList ddlCity, string countryCode)
{
// Binding code of city based selected country
}
您需要通過在後面的代碼中查找控件來設置下拉菜單中的SelectedIndexChanged事件的EmpCode和指定列。
我能夠得到的只有下拉列表的值的使用,我不能夠使用訪問GridView的任何其他列來自發件人的Parent.FindControl。納文的解決方案解決了!感謝您的回答。 – banupriya