RadioButtonList: Show selected

Ø

Øyvind Isaksen

I'm 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


I have tried this:
"Me.radTypeList.SelectedIndex = savedID" does not work.
"Me.radTypeList.SelectedItem = savedID" does not work either.


Thanks for all tips!!!
 
V

vinu

Hi

I believe radTypeList is name of your RadioButtonList control,
use
radTypeList .SelectedValue =savedID.toString()



e.g

ASP.Net page

<body >
<form id="form1" runat="server" >
<div>

<br />

<asp:RadioButtonList ID="RadioButtonList1" runat="server">
<asp:ListItem Value="1">1</asp:ListItem>
<asp:ListItem Value="2">2</asp:ListItem>
<asp:ListItem Value="3">3</asp:ListItem>
</asp:RadioButtonList>
</form>
</body>



Code behind page (c#)
protected void Page_Load(object sender, EventArgs e)

{

RadioButtonList1.SelectedValue = "2";

}


Hope this will solve your problem..



Vinu







"Øyvind Isaksen" <oyvind@

webressurs.no> wrote in message
news:%[email protected]...
 
Ø

Øyvind Isaksen

Hello!

I get the errormessage "Selectedvalue is not a member of
System.Web.UI.WebControls.RadioButtonList" when I try that...
I only have the choices of using "SelectedIndex" or "SelectedItem", there is
no "SelectedValue" on the radiobuttonlist-control.

Strange!?
 
Ø

Øyvind Isaksen

Hello,

It seems like it has to do with the framework version I use...
I run Visual Studio .Net with framework 1.0 (1.0.3705). I have updated now
Visual Studio with all new service releases, and installed Framework v.1.1
on my computer. But still it seems like visual studio uses framevork 1.0.

Framework 1.0 dont support the "SelectedValue" Property (RadioButtonList
control).
In the Microsoft documentation Microsoft writes: "Note: This namespace,
class, or member is supported only in version 1.1 of the .NET Framework."

Do you know how to fix this??
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top