0

I need to get the value of the selected item in a dropdown list that's inside the edit template of a formview control. The formview ID is "fvDocRvwrs".

Here's the markup for the dropdownlist:

<asp:DropDownList SelectedValue='<%# Bind("rvwStat") %>' runat="server" ID="rvwStatDdl" CssClass="form-control" DataSourceID="sdsStatuses" DataTextField="stat" DataValueField="statIdPk" AppendDataBoundItems="true" OnSelectedIndexChanged="rvwStatDdl_SelectedIndexChanged"><asp:ListItem Value="">--Please Select--</asp:ListItem></asp:DropDownList>

I'm just having some difficulty getting the SelectedValue using the onselectedindexchanged event of the dropdownlist. I am able to find the control using:

protected void rvwStatDdl_SelectedIndexChanged(object sender, EventArgs e)
    {
        var statVal = fvDocRvwrs.FindControl("rwStatDdl").ToString();
    }

I just need to know how to populate a variable with the selected value.

user1916528
  • 379
  • 4
  • 23

2 Answers2

2

I think you should cast as DropDownList after finding control

var statVal = ((DropDownList)fvDocRvwrs.FindControl("rwStatDdl")).SelectedValue.ToString();
Arslan Ali
  • 450
  • 4
  • 12
0

You can access the SelectedValue property.

Try protected void name_SelectedIndexChanged(object sender, EventArgs e){ DropDownList list = (DropDownList)sender; string value = list.SelectedValue;}

Credit: Dropdownlist selected value at Selectedindexchanged event Frank Lee's answer