473,378 Members | 1,549 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Programmatically Selecting Item in Radio Button List

I have created a radio button list programmatically.

C#
SqlConnection conn = new SqlConnection("data source=localhost;
integrated security=true; initial catalog=pubs");
SqlCommand cmdAuthors = new SqlCommand("select * from Authors", conn);
SqlDataReader dr;
dr = cmdAuthors.ExecuteReader();
RadioButtonList rblAuthors = new RadioButtonList();
rblAuthors.DataSource = dr;
rblAuthors.DataTextField = "au_fname" + " " + "au_lname";
rblAuthors.DataBind();
dr.Close();
conn.Close();

The first item in the radio button list should be "Johnson White" as
he is the first author in the authors table of the pubs database. He
is the first author because the index on the table is on SSN and he
has the lowest SSN.

Now I want to programmatically "select" the radio button associated
with the listitem that corresonds to "Johnson White." I don't want
the user to make that selection; I want the application to do it on a
page load for example. How do I write the code to "select" or "check"
a radio button item in a radio button itemlist programmatically?

Any help or suggestions will be greatly appreciated.

Thanks,

John Criswell
Nov 17 '05 #1
1 9958
Ray,

Your code worked perfectly and did exactly what I wanted it to do. You
said that you had some difficulties with my code. I apologize for that.
I didn't test it to see if it would work. I just put down some sample
code using the famous "pubs" database to communicate my concept. I'm
sorry if my code caused you some difficulties.

On the bright side, I plugged your method into my project, and it worked
the first time. You are an outstanding C# ASP.NET programmer.

Many thanks,

John Criswell

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Fritz | last post by:
I know it, I know it. It's come up a lot. I've done the Googling, but the standard answer doesn't do what I expect it to. For the record, the standard answer is: "Set the Selected property of a...
6
by: Hazzard | last post by:
I store radiobuttonlist values in the db using the string value of the radio button item value. (nvarchar) I am creating an edit functionality on the asp.net form so that when I reuse my...
1
by: sneha123 | last post by:
There will be some 20 questions and for each question there will be 4 choices.what i want to do is to select multiple answers by clicking the checkbox. i m using asp.net,vb.net pls help me we...
2
by: Mike Kelly | last post by:
Hi. I have a data table where rows are grouped according to a certain criteria and I want to be able to display all the rows that belong to the same group together on the screen. In addition, I...
3
by: newjazzharmony | last post by:
Hello group, I want to automatically select a specific checkbox when a user clicks (selects) a specific item in a radiobutton group. Both controls are in the same form. Let's say for...
16
by: Vikas Kumar | last post by:
i am selectin some data from database and through reader showing it in datalist as above now for radio buttons i have single column which returns 1,2,3 and according to that i want one of above...
0
by: Bruce | last post by:
I am using a radio button list inside datagrid. I am binding data to the radio button list using DataBind(). Can any one tell me the easiest way for showing item number for items in the Radio...
1
by: Bruce | last post by:
I am using a radio button list inside datagrid. I am binding data to the radio button list using DataBind(). Can any one tell me the easiest way for showing item number for items in the Radio...
7
by: IchBin | last post by:
I am trying to programmatically set a radio button in a table of radio buttons. I have two problems with the code below: 1 - I can not prepare the <Formstatement to be printed by php. (syntax...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.