Professional Web Applications Themes

Programmatically Selecting Item in Radio Button List - ASP.NET General

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 ...

  1. #1

    Default 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
    John Criswell Guest

  2. #2

    Default Re: Programmatically Selecting Item in Radio Button List

    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 [url]http://www.developersdex.com[/url] ***
    Don't just participate in USENET...get rewarded for it!
    John Criswell Guest

Similar Threads

  1. Radio Button & List to search - ASP
    By Tag2007 in forum Macromedia Dynamic HTML
    Replies: 0
    Last Post: July 27th, 11:01 AM
  2. How to put a full radio button list in each row of datagrid?
    By John Smith in forum ASP.NET Data Grid Control
    Replies: 1
    Last Post: August 20th, 12:27 AM
  3. radio button list doesn't hold value?
    By KathyB in forum ASP.NET General
    Replies: 2
    Last Post: August 12th, 02:46 AM
  4. how to make columns the same size in a radio button list
    By Trevor Hartman in forum ASP.NET General
    Replies: 1
    Last Post: August 1st, 05:55 PM
  5. Radio Button List server control and java script
    By jayuya in forum ASP.NET General
    Replies: 2
    Last Post: July 3rd, 08:22 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139