Bind DataTable to asp:RadioButtonList : RadioButtonList « Data Binding « ASP.Net

ASP.Net
1. ADO.net Database
2. Asp Control
3. Collections
4. Components
5. Data Binding
6. Development
7. HTML Control
8. Mobile Control
9. Page
10. Request
11. Response
12. Server
13. Session Cookie
14. User Control and Master Page
15. Validation by Control
16. Validation by Function
17. XML
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
ASP.Net » Data Binding » RadioButtonList 
Bind DataTable to asp:RadioButtonList

<%@ Page Language=VB Debug=true %>
<%@ Import Namespace="System.Data" %>
<script runat=server>
Sub Page_Load(ByVal Sender as Object, ByVal E as EventArgs)
    If Not IsPostBack Then
        Dim MyDT As New DataTable
        Dim MyRow As DataRow
        MyDT.Columns.Add(New DataColumn("DepartmentID", _
            GetType(Int32)))
        MyDT.Columns.Add(New DataColumn("DepartmentName", _
            GetType(String)))
        MyRow = MyDT.NewRow()
        MyRow(01
        MyRow(1"Marketing"
        MyDT.Rows.Add(MyRow)
        MyRow = MyDT.NewRow()
        MyRow(02
        MyRow(1"Sales"
        MyDT.Rows.Add(MyRow)
        MyRow = MyDT.NewRow()
        MyRow(03
        MyRow(1"Support"
        MyDT.Rows.Add(MyRow)
        MyRow = MyDT.NewRow()
        MyRow(04
        MyRow(1"Customer Service"
        MyDT.Rows.Add(MyRow)
        rbl2.DataSource = MyDT
        rbl2.DataBind()
        rbl2.Items(3).Selected=True
    End If
End Sub
Sub rbl1_Clicked(sender As Object, e As EventArgs)
    lblMessage.Text = "Preferred office color:<BR>" _
        & rbl1.SelectedItem.Text & "<BR>"
End Sub
Sub rbl2_Clicked(sender As Object, e As EventArgs)
    lblMessage2.Text = "ID of Department you work in:<BR>" _
        & rbl2.SelectedItem.Value & "<BR>"
End Sub
</SCRIPT>
<HTML>
<HEAD>
<TITLE>RadioButtonList Control Sample Page</TITLE>
</HEAD>
<BODY  >
<form runat="server">
<Font Face="Tahoma">
<asp:Label
    id="lblMessage"
    runat="server"
    Font-Bold="True"
    Text="Preferred office color:"
/>
<asp:RadioButtonList 
    id="rbl1" 
    runat="server"
    CellPadding="5"
    CellSpacing="5"
    RepeatColumns="3"
    RepeatDirection="Vertical"
    RepeatLayout="Table"
    TextAlign="Right"
    AutoPostBack="True"
    OnSelectedIndexChanged="rbl1_Clicked"
>
    <asp:ListItem>Blue</asp:ListItem>
    <asp:ListItem>Red</asp:ListItem>
    <asp:ListItem>Green</asp:ListItem>
    <asp:ListItem>Purple</asp:ListItem>
    <asp:ListItem>Black</asp:ListItem>
    <asp:ListItem Selected>Gold</asp:ListItem>
</asp:RadioButtonList>
<HR>
<asp:Label
    id="lblMessage2"
    runat="server"
    Font-Bold="True"
    Text="ID of Department you work in:<BR>"
/>
<BR>
<asp:RadioButtonList 
    id="rbl2" 
    runat="server"
    AutoPostBack="True"
    OnSelectedIndexChanged="rbl2_Clicked"
    DataTextField="DepartmentName"
    DataValueField="DepartmentID"
    BackColor = "LightYellow"
    ForeColor = "DarkRed"
    BorderColor = "DarkBlue"
    BorderStyle = 8
    TextAlign="Left"
    RepeatLayout="Table"
>
</asp:RadioButtonList>

</Font>
</Form>
</BODY>
</HTML>
           
       
Related examples in the same category
w__w_w__.jav_a__2__s___.c_o__m___ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.