前台DropDownList动态取得值 ,后台无法获取SelectedValue
前台
<asp:TableRow Height="25">
<asp:TableCell ID="TableCell8" Text="分类:" />
<asp:TableCell ID="TableCell16" cssClass="tb_edit_text" >
<asp:DropDownList ID="feilei" AutoPostBack="true" runat="server" DataSourceID="SqlDataSource1" DataTextField="feilei" DataValueField="feilei" onselectedindexchanged="DropDownList1_SelectedIndexChanged"></asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:waternewsConnectionString %>" SelectCommand="select feilei from jcsj group by feilei"></asp:SqlDataSource>
</asp:TableCell>
</asp:TableRow>
后台
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
string feilei = feilei.SelectedValue;//这句有错
..........
}
------解决方案--------------------局部变量的名字和你的DropDownList的ID重名 导致编译器认为feilei.SelectedValue是前面声明的局部变量的 所以报错了 换个命名就好了
string feilei = feilei.SelectedValue;