In this article we will introduce with How to add item in RadioButtonList using DataSource in ASP.NET
How to add item in RadioButtonList using DataSource in ASP.NET
In this example You can see how we can add item in RadioButtonList using DataSource. In this example we use SqlDataSource for bind the data with RadioButtonList.
RadioButtonListDataSource.aspx (Design Page):
RadioButtonListDataSource.aspx (source code):
<%@ Page Title="" Language="C#" MasterPageFile="~/RoseindiaMaster.master" AutoEventWireup="true" CodeFile="RadioButtonListDataSource.aspx.cs" Inherits="RadioButtonListDataSource" %> <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server"> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server"> <div> <h2 style="color: Green"> How to add item in RadioButtonList <br /> using DataSource in ASP.NET 4, C#</h2> <asp:RadioButtonList ID="RadioButtonList1" runat="server" DataSourceID="SqlDataSource1" DataTextField="ProductName" DataValueField="ProductName" RepeatColumns="3" BackColor="Black" Font-Names="Verdana" Font-Size="Small" ForeColor="White" AutoPostBack="True" OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged"> </asp:RadioButtonList> <br /> <asp:Label ID="Label1" runat="server" Font-Bold="True" Font-Names="Verdana" Font-Size="Small" ForeColor="#000099" /> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ChartDatabaseConnectionString %>" SelectCommand="SELECT [ProductName] FROM [Product]"></asp:SqlDataSource> </div> </asp:Content>
RadioButtonListDataSource.aspx (C# code file):
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class RadioButtonListDataSource : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e) { Label1.Text = " You choose : " + RadioButtonList1.SelectedItem.ToString(); } }
Output:
Download source code
[ 0 ] Comments