你需要把你的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