How To Get Text and Value Of DropdownList Using ButtonClick

In this article i will explain how to get selected value and text of dropdownlist 
<!DOCTYPE html>
 <form id="form1" runat="server">
    <div>
        <asp:DropDownList ID="DropDownList1" runat="server">
            <asp:ListItem Text="Select Course" Value="-1"></asp:ListItem>

            <asp:ListItem Text="Asp.net" Value="1"></asp:ListItem>
            <asp:ListItem Text="SQL" Value="2"></asp:ListItem>
            <asp:ListItem Text="C#" Value="3"></asp:ListItem>
            <asp:ListItem Text="jquery" Value="4"></asp:ListItem>
        </asp:DropDownList>
        <br />
        <asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click" />
    </div>

    </form>

   protected void btnSubmit_Click(object sender, EventArgs e)
    {
        string Course = DropDownList1.SelectedItem.Text;
        int Value =Convert.ToInt32(DropDownList1.SelectedValue);

    }


No comments:

Post a Comment