J
John Criswell
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
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