Home > ASP.Net > Bind RadioButtonList

Bind RadioButtonList

try this example to bind RadiobuttonList control
i have table in my database called Category has the following fields:

  • Id (int , PK)
  • Name (nvarchar(50))
  • Pic (nvarchar(50))

as i save image name in database and upload image in folder in my website

now i want to bind this table to Radiobuttonlist

where the value of radiobuttonlist should be Id from my table


  public DataSet Bind()
        string connectionstring = ConfigurationManager.ConnectionStrings["eLocalize_ConnStr"].ConnectionString.ToString();
        SqlConnection conn = new SqlConnection(connectionstring);
        string command = "select Id ,Price ,Image from Car";
        SqlCommand comm = new SqlCommand();
        comm.CommandText = command;
        comm.Connection = conn;
        SqlDataAdapter da = new SqlDataAdapter();
        da.SelectCommand = comm;
        DataSet ds = new DataSet();
        return ds;

    protected void Page_Load(object sender, EventArgs e)
        DataSet ds = new DataSet();
        ds = Bind();
        foreach (DataRow dr in ds.Tables[0].Rows)
            ListItem li = new ListItem();
            li.Text = "< i mg  s rc=\"Car_Image/" + dr[2].ToString() + "\" alt=\"\" />&nbsp;" + dr[1].ToString();  // This will display the image next to the text
            li.Value = dr[0].ToString();

Good Luck

Categories: ASP.Net
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: