Link to home
Start Free TrialLog in
Avatar of webressurs
webressursFlag for Norway

asked on

RadioButtonList / DropDownList: Show selected

I am making a page to update articles.
When a radiobuttonlist is displayed, I want the stored value to be displayed as default (checked).

Example: I use a procedure to display the RadioButtonList. An input to this procedure is the ID that is stored in the database. I want the radiobuttonlist to show the radiobutton with datavaluefield = savedID as checked when it is displayed.


Private Sub getTypes(ByVal savedID)
    Dim conn As New SqlConnection(variables.ConnString)
    Dim cmd As New SqlCommand("spShowType", conn)
    cmd.CommandType = CommandType.StoredProcedure

    cmd.Connection.Open()
    Dim dr As SqlDataReader = cmd.ExecuteReader
    Me.radTypeList.DataSource = dr
    Me.radTypeList.DataTextField = "content"
    Me.radTypeList.DataValueField = "typeID"
    'Me.radTypeList.SelectedIndex = savedID

    Me.radTypeList.DataBind()
    cmd.Connection.Close()
    cmd.Dispose()
    conn.Dispose()
End Sub


"SelectedIndex" does not check the radiobutton where datavaluefiled = savedID...

Thanks for all tips!!!
Avatar of TimCottee
TimCottee
Flag of United Kingdom of Great Britain and Northern Ireland image

Hi webressurs,

Use radTypeList.SelectedValue = savedID instead, the selectedindex only selects (doesn't check) whereas setting the selected value does.

Tim Cottee
Avatar of bsdotnet
bsdotnet

If savedID is same value as "TypeID" then use
            Me.radTypeList.SelectedValue = savedID
Avatar of webressurs

ASKER

I get the errormessage "Selectedvalue is not a member of System.Web.UI.WebControls.RadioButtonList" when I try that...
Since you have installed .net 1.1, guess the above problem will be resolved.

Just realised that you are the one created the another thread.
Hello,

This is the way, framework 1.0 dont support the property SelectedValue:
Me.radTypeList.Items.FindByValue(savedID).Selected = True

Thanks for all tips :)
ASKER CERTIFIED SOLUTION
Avatar of GranMod
GranMod

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