programming we consider all important topic for knowledge about controls,web Services, JSON, Ajax, database, and interview related Question. In this and sql server tutorial blog we give many examples of jquery as like How Play YouTube Video in Your Website by URL, How to Play YouTube Videos in by using Jquery , Jquery Change div background on mouseover in , JQuery UI Datepicker (Calendar) etc.

Tuesday, August 5, 2014

How To bind RadioButtonList Control From data base

Radio List Control bind from Sql database:

In programming tutorial today I want to see “Binding of RadiobuttonList from Sql data base”. as we know that Button list control is used to create a group of radio buttons.In this the list elements are used to define items in Button groups. And we also know buttonlist control support data from the data base and display this data as a buttonlist items.

Use Sql data Base And Display data in RadioButton control List: web programming by C# in which the developer face problem to binding data in Radiobutton. The most important Question is this. When we visit many web sites for solving this Question

Data binding Example of Button control:

 I remember that when we starting web development then we face this type of problems much time.
Here we just try to display data into radio button from database. code for .aspx page for declare a buttonlist:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="">
<head runat="server">
    <form id="form1" runat="server">
    <asp:radiobuttonlist ID="rblCountryList" runat="server"></asp:radiobuttonlist>
     <asp:Button ID="btn" runat="server" Text="ok" OnClick="btnSubmit_Click" /><br />
     <asp:Label ID="lblMsg" runat="server"></asp:Label> 
</html> code with C# for .aspx.cs page for bind data buttonlist:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page
    SqlConnection conn = new SqlConnection("Data Source=localhost;Initial Catalog=Demo;User ID=sa;Password=sa123");
    protected void Page_Load(object sender, EventArgs e)
        if (!IsPostBack)
            BindList();// call function here........................

    void BindList()//...........define function here......................
        DataSet ds = new DataSet();//create data base instanse...................
        string cmdstr = "select id,country from Countrylist";//sql query for fecthing data..............
        SqlDataAdapter adp = new SqlDataAdapter(cmdstr, conn);
        if (ds.Tables[0].Rows.Count > 0)
            rblCountryList.DataSource = ds;
            rblCountryList.DataTextField = "country";
            rblCountryList.DataValueField = "id";
            lblMsg.Text = "There are no dat in data base ..................";

    protected void btnSubmit_Click(object sender, EventArgs e)
        lblMsg.Text = rblCountryList.SelectedItem.ToString();


 Other Radio Button Related Post:

No comments:

Post a Comment