在按钮单击事件中获取代码后面的下拉列表的第一个值 [英] Getting first value of dropdownlist in Code behind on button click event
本文介绍了在按钮单击事件中获取代码后面的下拉列表的第一个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我的aspx页面中有五个下拉列表,其中有静态值,按钮上的点击事件有一个按钮,我想要下拉列表的值在标签中但是当我点击按钮时,下拉列表会自动显示第一个值,
所以代码背后我总是得到第一个值,
Hi All,
I have five dropdownlist in my aspx page where there is static values and one button on click event on the button i want the values of dropdownlist in Label but when i m clicking the button the dropdownlist automatically appears the first value,
so in code behind i m getting the first value always,
<asp:DropDownList ID="drpProduct" runat="server" Width="104%" Style="margin-top: -4.2%; margin-left: 16px">
<asp:ListItem Value="--Select Product--"></asp:ListItem>
<asp:ListItem Value="All">All Product</asp:ListItem>
<asp:ListItem Value="Cotton S6">Cotton S6</asp:ListItem>
<asp:ListItem Value="Cotton S5">Cotton S5</asp:ListItem>
<asp:ListItem Value="Stone x 1">Stone x 1</asp:ListItem>
<asp:ListItem Value="Stone x 2">Stone x 1</asp:ListItem>
</asp:DropDownList>
<asp:Button ID="btnSearch" runat="server" CssClass="btn green" Text="Search" ValidationGroup="val" UseSubmitBehavior="false" OnClick="btnSearch_Click" />
背后的代码是:
And code behind is:
lblProduct.Text = drpProduct.SelectedValue;
请指导我...
Please guide me on this...
推荐答案
http://www.aspsnippets。 com / Articles / Get-selected-of-HTML-Select-DropDownList-in-ASPNet-code-behind-using-C-and-VBNet.aspx [ ^ ]
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
// bind your dropdown here
}
}
protected void btnSearch_Click(object sender, EventArgs e)
{
Response.Write(drpProduct.SelectedValue);
}
这篇关于在按钮单击事件中获取代码后面的下拉列表的第一个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文