开发者

Get selected Value from dropdownlist after submit?

开发者 https://www.devze.com 2022-12-30 18:19 出处:网络
I populate DropDownList in ASP.NET webforms: <asp:DropDownList runat=\"server\" ID=\"salesman\"></asp:DropDownList>

I populate DropDownList in ASP.NET webforms:

<asp:DropDownList runat="server" ID="salesman"></asp:DropDownList>


users= Buslayer.GetSalesRep();

foreach (userentity user in users)
{         
      salesman.Items.Add(new ListItem(user.FirstName + "开发者_开发问答 " + user.LastName,
                                      user.UserID.ToString())); 
}

After submission, I am still getting selected index = 0,

I tried all of this but failed:

Response.Write("" + salesman.SelectedValue);
Response.Write("" + salesman.SelectedItem.Value);
Response.Write("" + salesman.SelectedIndex);


Are you checking for the Page posting back with you databind?

Your page load should look something like:

protected void Page_Load(object sender, EventArgs e)
{
    if(!IsPostBack)
    {
        BindData();
    }

}

protected void BindData()
 {
    // Get your data
    ddl.DataSource = yourData;
    ddl.DataBind();

}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号