seckel
asked on
Unable to bind RadioButtonList within repeater.
I have a repeater with a RadioButtonList. I can bind the repeater, but I can't seem to bind the RadioButtonList.
Any suggestion???
Below is my code:
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.Sql Client" %>
<script language="VB" runat="server">
Dim SQL as String = ""
Dim connection = "..."
Dim dbConnection as SqlConnection
Dim dbCommand As SQLCommand
Dim dbReader as sqldatareader
Dim skillCount as Long
Dim employee as String
<%--
The following variable 'message' is used for code rended blocks or inline script.
This is used for example only.
--%>
Dim message as String
Sub Page_Load(sender As Object, e As EventArgs)
If not Page.IsPostBack Then
'-- Do the following on initial page load.
'-- Initial value for employeeId until it can be obtained by user logon
employee = "441"
BindGrid()
End If
End Sub
Sub BindGrid()
'------------------------- ---------- ---------- ---------- ---------- ---------- ----
' Get the skills and proficiencies.
'------------------------- ---------- ---------- ---------- ---------- ---------- ----
'-- Open a database connection
dbConnection.Open()
'-- Return the count of recordset
SQL = "SELECT COUNT(*)" _
& " FROM dbo.tbl_rl_skill a, dbo.tbl_rl_proficiency b" _
& " WHERE b.emp_id = " & employee _
& " AND b.skill_id = a.skill_id"
dbCommand = New SQLCommand(SQL, dbConnection)
'-- Return SQL function value from the table
skillCount = dbCommand.ExecuteScalar()
'-- Bind the control only if records are returned
If dbCommand.ExecuteScalar() <> 0 Then
'-- Create and issue an SQL command through the database connection
SQL = "SELECT a.skill, b.proficiency" _
& " FROM dbo.tbl_rl_skill a, dbo.tbl_rl_proficiency b" _
& " WHERE b.emp_id = " & employee _
& " AND b.skill_id = a.skill_id"
dbCommand = New SQLCommand(SQL, dbConnection)
'-- Create a recordset of selected records from the database
dbReader = dbCommand.ExecuteReader()
'-- Bind the recordset to a control
repeater1.DataSource = dbReader
repeater1.DataBind()
radioList1.DataSource = dbReader
radioList1.DataValueField = "proficiency"
radioList1.DataBind()
End If
'-- Close the reader and database connections
dbReader.Close()
dbConnection.Close()
End Sub
</script>
<html>
<head>
</head>
<body>
<form runat="server">
</p>
<asp:repeater id="repeater1" runat="server">
<HeaderTemplate>
<table width="100%" style="font: 7pt verdana">
<tr style="background-color:DF A894">
<th align="left">
Skill
</th>
<th>
Proficiency
</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr style="background-color:FF ECD8">
<td align="left">
<%# DataBinder.Eval(Container. DataItem, "skill") %>
</td>
<td align="center">
<asp:RadioButtonList id="radioList1" runat="server" RepeatColumns="4">
<asp:ListItem Value="0" Text="" />
<asp:ListItem Value="1" Text="" />
<asp:ListItem Value="2" Text="" />
<asp:ListItem Value="3" Text="" />
</asp:RadioButtonList>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
<tr style="font-size:7pt">
<td align ="left" >
<%= skillCount & " skills" %>
</td>
<td align="right" colspan="4">
xxxxxl
</td>
</tr>
</table>
</FooterTemplate>
</asp:repeater>
</form>
</body>
</html>
Any suggestion???
Below is my code:
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.Sql
<script language="VB" runat="server">
Dim SQL as String = ""
Dim connection = "..."
Dim dbConnection as SqlConnection
Dim dbCommand As SQLCommand
Dim dbReader as sqldatareader
Dim skillCount as Long
Dim employee as String
<%--
The following variable 'message' is used for code rended blocks or inline script.
This is used for example only.
--%>
Dim message as String
Sub Page_Load(sender As Object, e As EventArgs)
If not Page.IsPostBack Then
'-- Do the following on initial page load.
'-- Initial value for employeeId until it can be obtained by user logon
employee = "441"
BindGrid()
End If
End Sub
Sub BindGrid()
'-------------------------
' Get the skills and proficiencies.
'-------------------------
'-- Open a database connection
dbConnection.Open()
'-- Return the count of recordset
SQL = "SELECT COUNT(*)" _
& " FROM dbo.tbl_rl_skill a, dbo.tbl_rl_proficiency b" _
& " WHERE b.emp_id = " & employee _
& " AND b.skill_id = a.skill_id"
dbCommand = New SQLCommand(SQL, dbConnection)
'-- Return SQL function value from the table
skillCount = dbCommand.ExecuteScalar()
'-- Bind the control only if records are returned
If dbCommand.ExecuteScalar() <> 0 Then
'-- Create and issue an SQL command through the database connection
SQL = "SELECT a.skill, b.proficiency" _
& " FROM dbo.tbl_rl_skill a, dbo.tbl_rl_proficiency b" _
& " WHERE b.emp_id = " & employee _
& " AND b.skill_id = a.skill_id"
dbCommand = New SQLCommand(SQL, dbConnection)
'-- Create a recordset of selected records from the database
dbReader = dbCommand.ExecuteReader()
'-- Bind the recordset to a control
repeater1.DataSource = dbReader
repeater1.DataBind()
radioList1.DataSource = dbReader
radioList1.DataValueField = "proficiency"
radioList1.DataBind()
End If
'-- Close the reader and database connections
dbReader.Close()
dbConnection.Close()
End Sub
</script>
<html>
<head>
</head>
<body>
<form runat="server">
</p>
<asp:repeater id="repeater1" runat="server">
<HeaderTemplate>
<table width="100%" style="font: 7pt verdana">
<tr style="background-color:DF
<th align="left">
Skill
</th>
<th>
Proficiency
</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr style="background-color:FF
<td align="left">
<%# DataBinder.Eval(Container.
</td>
<td align="center">
<asp:RadioButtonList id="radioList1" runat="server" RepeatColumns="4">
<asp:ListItem Value="0" Text="" />
<asp:ListItem Value="1" Text="" />
<asp:ListItem Value="2" Text="" />
<asp:ListItem Value="3" Text="" />
</asp:RadioButtonList>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
<tr style="font-size:7pt">
<td align ="left" >
<%= skillCount & " skills" %>
</td>
<td align="right" colspan="4">
xxxxxl
</td>
</tr>
</table>
</FooterTemplate>
</asp:repeater>
</form>
</body>
</html>
ASKER
Ok, my binding now looks like this:
'-- Bind the recordset to a control
repeater1.DataSource = dbReader
repeater1.DataBind()
dbReader = dbCommand.ExecuteReader()
radioList1.DataSource = dbReader
radioList1.DataValueField = "proficiency"
radioList1.DataBind()
But I now get this message:
Compiler Error Message: BC30451: Name 'radioList1' is not declared.
My asp:RadioButtonList id="radioList1" is correct.
Any suggestions??
'-- Bind the recordset to a control
repeater1.DataSource = dbReader
repeater1.DataBind()
dbReader = dbCommand.ExecuteReader()
radioList1.DataSource = dbReader
radioList1.DataValueField = "proficiency"
radioList1.DataBind()
But I now get this message:
Compiler Error Message: BC30451: Name 'radioList1' is not declared.
My asp:RadioButtonList id="radioList1" is correct.
Any suggestions??
Radio button create problem in the DataList or DataGrid as it cant be grouped even if you assign the group name. See the following post:
https://www.experts-exchange.com/questions/21003207/asp-repeater-and-radiobuttons.html
I will recommend you use GlobalRadioButton which is free and can be downloaded from the following URL:
http://metabuilders.com/Tools/GlobalRadioButton.aspx
-Nauman
https://www.experts-exchange.com/questions/21003207/asp-repeater-and-radiobuttons.html
I will recommend you use GlobalRadioButton which is free and can be downloaded from the following URL:
http://metabuilders.com/Tools/GlobalRadioButton.aspx
-Nauman
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Best, Nauman