我想开发3个下拉列表城市,州,国家。当我选择国家/地区时,它应该只显示与城市和州/地区相同的国家/地区
ASP.NET代码:
<asp:GridView ID="GridView1" runat="server" AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="Id" DataSourceID="manager" OnRowEditing="GridView1_RowEditing">
<Columns>
<asp:CommandField ShowEditButton="True" ShowSelectButton="True" />
<asp:BoundField DataField="Id" HeaderText="Id" InsertVisible="False" ReadOnly="True" SortExpression="Id" />
<asp:BoundField DataField="username" HeaderText="username" ReadOnly="True" SortExpression="username" />
<asp:TemplateField HeaderText="ma_city" SortExpression="ma_city">
<EditItemTemplate>
<asp:DropDownList ID="ddl_city" runat="server" AutoPostBack="True" SelectedIndex='<%# Eval("city_id") %>' SelectedValue='<%# Bind("ma_city") %>' DataSourceID="city">
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("ma_city") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="ma_state" SortExpression="ma_state">
<EditItemTemplate>
<asp:DropDownList ID="ddl_state" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList5_SelectedIndexChanged1" SelectedIndex='<%# Bind("state_id") %>' SelectedValue='<%# Bind("ma_state") %>' DataSourceID="state">
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("ma_state") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="ma_country" SortExpression="ma_country">
<EditItemTemplate>
<asp:DropDownList ID="ddl_country" runat="server" AutoPostBack="True" DataSourceID="country" DataTextField="name" DataValueField="Id" OnSelectedIndexChanged="DropDownList4_SelectedIndexChanged" SelectedIndex='<%# Eval("countrt_id") %>' SelectedValue='<%# Bind("ma_country") %>'>
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("ma_country") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="ma_pincode" HeaderText="ma_pincode" SortExpression="ma_pincode" />
<asp:BoundField DataField="Ma_phone_no" HeaderText="Ma_phone_no" SortExpression="Ma_phone_no" />
</Columns>
</asp:GridView>
并且我还在每个事件中使用下面的代码,例如(这是在visualstudio 2017中自动生成的):
DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
GridView1_SelectedIndexChanged(object sender, EventArgs e)
我使用两种类型的代码通过以下方式获取gridview引用:
GridView gridView = (GridView)((((Control)sender).Page.Items[GridView1]));
GridViewRow gridViewRow = gridView.SelectedRow;
DropDownList dpl5 = (DropDownList)gridViewRow.FindControl("ddl_state");
DropDownList dpl6 = (DropDownList)gridViewRow.FindControl("ddl_city");
代码:-
GridViewRow gridViewRow = GridView1.SelectedRow;
DropDownList dpl5 = (DropDownList)gridViewRow.FindControl("ddl_state");
DropDownList dpl6 = (DropDownList)gridViewRow.FindControl("ddl_city");
这两个都给我null作为回报。