Having trouble with a RadioButtonList control

M

Mark Broadbent

try as I might (and using different properties) this control always seems to
be returning the first element of the control as the "selected" item even
though I am selecting the second element. All I need it the index number to
reference a particular row num of a dataset. I only just noticed this today
but it if I cant determine the selected radiobuttonlist item then it reders
this control useless.

Hope someone can help?

--
Br,

Mark Broadbent

Mark Broadbent

mcad, mcdba , mcse+i
 
M

Mark Broadbent

protected System.Web.UI.WebControls.RadioButtonList RadioButtonList1;



/*This bit is from the page load event which dynamically builds each button
for each row*/

foreach (System.Data.DataRow r in dsTalks1.Tables[0].Rows)

{//Do not want to show the video id in dataset so start index at 1

sb.Append("Talk ID:" + r.ItemArray[1].ToString() + ", ");

sb.Append(r.ItemArray[2].ToString() + ", ");

sb.Append(r.ItemArray[3].ToString() + ", ");

sb.Append(r.ItemArray[4].ToString());


this.RadioButtonList1.Items.Add(sb.ToString());

this.RadioButtonList1.Items[0].Selected = true;

//Clear string builder for next cycle

sb.Remove(0, sb.Length);}



/*And this bit is from my button click event handler which should find the
selected radiobutton - but always returns the first item*/

while (this.RadioButtonList1.Items[talkselected].Selected != true)

{talkselected ++;}

//Change videoid in the dataset

System.Data.DataRow row = this.dsTalks1.Tables[0].Rows[talkselected];
 
S

Saravana

Check for ispostback property in pageload before setting radiobuttonlist
selected property otherwise when the button clicked postback fires, it will
set the selectedindex to first row.

--
-Saravana
http://dotnetjunkies.com/WebLog/saravana/
www.ExtremeExperts.com

Mark Broadbent said:
protected System.Web.UI.WebControls.RadioButtonList RadioButtonList1;



/*This bit is from the page load event which dynamically builds each button
for each row*/

foreach (System.Data.DataRow r in dsTalks1.Tables[0].Rows)

{//Do not want to show the video id in dataset so start index at 1

sb.Append("Talk ID:" + r.ItemArray[1].ToString() + ", ");

sb.Append(r.ItemArray[2].ToString() + ", ");

sb.Append(r.ItemArray[3].ToString() + ", ");

sb.Append(r.ItemArray[4].ToString());


this.RadioButtonList1.Items.Add(sb.ToString());

this.RadioButtonList1.Items[0].Selected = true;

//Clear string builder for next cycle

sb.Remove(0, sb.Length);}



/*And this bit is from my button click event handler which should find the
selected radiobutton - but always returns the first item*/

while (this.RadioButtonList1.Items[talkselected].Selected != true)

{talkselected ++;}

//Change videoid in the dataset

System.Data.DataRow row = this.dsTalks1.Tables[0].Rows[talkselected];



Mark Sandfox said:
Post your code please. I think you simply have a delcaration problem.
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top