Link to home
Start Free TrialLog in
Avatar of NerishaB
NerishaBFlag for South Africa

asked on

ASP Dropdown Passing Databound selection value

Hi,

I have created an ASP dropdown, and used the wizard to bind the data to the list.  Now, I want to pass the result back so that I may use it in the codebehind, but I dont know how to do this.

See my aspx code here:  My Codebehind is attached below.  I need to pass the selection in the "Submit" function.

<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource1"
        DataTextField="FullName" DataValueField="Personel_ID" Height="27px"
        Width="218px" AutoPostBack="True"
        onselectedindexchanged="DropDownList1_SelectedIndexChanged"
        AppendDataBoundItems="True">
<asp:ListItem Text="(All)" Value="defaultValue" Selected="true"></asp:ListItem>

</asp:DropDownList>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server"
        ConnectionString="ConnectionString">
    </asp:SqlDataSource>
protected void submit(object sender, EventArgs e)
        {
            Class1 c1 = new Class1();
            DateTime FromDate= DateTime.Parse(Request.Form[TextBox1.UniqueID]);
            DateTime toDate = DateTime.Parse(Request.Form[TextBox2.UniqueID]);
            
            
            IDataReader reader = c1.getData(FromDate, toDate, FullName);
             GridView1.DataSource = reader;
             GridView1.DataBind();

Open in new window

Avatar of Pratima
Pratima
Flag of India image

On the same page on button event you will get selected values using

DropDownList1.SelectedItem.value
In your casetry like thi s

string str = HttpContext.Current.Request.Form[varDropDownList.UniqueID];

or

string str = Request.Form[varDropDownList.UniqueID];
ASKER CERTIFIED SOLUTION
Avatar of Pratima
Pratima
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of NerishaB

ASKER

Thanks