简体   繁体   中英

Unable to retrieve selected dropdownlist value of ASP.NET webform in C# .cs file

I am trying to access selected dropdownlist data in .cs file but unable to fetch same. I am fetching data in dropdownlist from mysql database.

.aspx code:

    <asp:DropDownList ID="ddrc_name" runat="server" Height="22px" Width="155px"></asp:DropDownList>

    <asp:Button ID="display_btn" runat="server" Text="Display" Height="37px"  Width="125px" OnClick="display_btn_Click" />

.cs code:

protected void display_btn_Click(object sender, EventArgs e)
{
    string rc_name =  Request.Form["ddrc_name"];
    String category = "Painter";

    Response.Redirect("~/dispay_rate_card.aspx?rc_name="+rc_name+"&category="+category);
}

How can I fetch selected dropdown data in .cs file from webform?

Have you tried:

var selectedText = rc_name.SelectedItem.Text;
var selectedValue = rc_name.SelectedItem.Value;

Thanks for helping. I am able to fetch DropDownList selected data from Webform if I directly create webform rather than using Master template.

String dd = Request.Form["DropDownList1"];

If I am creating webform using master page then unable to fetch selected data of DropDownList.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM