我在gridview中有一个下拉列表,如下所示
<asp:GridView ID="GridView1" runat="server" CellPadding="4" AutoGenerateColumns="false" ForeColor="#333333" GridLines=">
<AlternatingRowStyle BackColor="White" />
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F5F7FB" />
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
<SortedDescendingCellStyle BackColor="#E9EBEF" />
<SortedDescendingHeaderStyle BackColor="#4870BE" />
<Columns>
<asp:TemplateField HeaderText="Field">
<ItemTemplate>
<asp:Label ID="lblService" runat="server" Text='<%# Eval("Name") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Area">
<ItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" >
<asp:ListItem Value="">Select</asp:ListItem>
<asp:ListItem Value="RowArea">RowArea</asp:ListItem>
<asp:ListItem Value="ColumnArea">ColumnArea</asp:ListItem>
<asp:ListItem Value="DataArea">DataArea</asp:ListItem>
<asp:ListItem Value="FilterArea">FilterArea</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
并且我在gridview之外有一个按钮。当我单击按钮时,我想在label和dropdownlist中的gridview中检索值
foreach (GridViewRow gvrow in GridView1.Rows)
{
Label lbl = (Label)gvrow.FindControl("lblService");
String field = lbl.Text;
DropDownList ddl1 = (DropDownList)gvrow.FindControl("DropDownList1");
String areatype = ddl1.SelectedItem.Value;
String value = ddl1.SelectedValue;
String result = field + "," + areatype;
objList.Add(result);
}
但是当我在按钮上单击执行上面的代码时,我得到了标签值,但下拉列表值始终显示默认值而不是所选值。