DataGrid Demo Using Andy Smith's RowSelectorColumn
This demo illustrates how to use Andy Smith's RowSelectorColumn control to create a column of radio buttons
in a DataGrid. Check out Andy Smith's controls (which are free and include source code) by visiting
MetaBuilders.com.
Source Code
<% @Import Namespace="System.Data" %>
<% @Import Namespace="System.Data.SqlClient" %>
<%@ Register TagPrefix="mbrsc" Namespace="MetaBuilders.WebControls" Assembly="MetaBuilders.WebControls.RowSelectorColumn" %>
<script language="vb" runat="server">
Sub Page_Load(sender as Object, e as EventArgs)
If Not Page.IsPostBack then
BindData()
End If
End Sub
Sub BindData()
'1. Create a connection
Dim myConnection as New SqlConnection(ConfigurationSettings.AppSettings("connectionString"))
'2. Create the command object, passing in the SQL string
Const strSQL as String = "sp_Popularity"
Dim myCommand as New SqlCommand(strSQL, myConnection)
'Set the datagrid's datasource to the datareader and databind
myConnection.Open()
dgPopularFAQs.DataSource = myCommand.ExecuteReader(CommandBehavior.CloseConnection)
dgPopularFAQs.DataBind()
End Sub
Sub RecordVote(sender as Object, e as EventArgs)
Dim rsc as RowSelectorColumn = RowSelectorColumn.FindColumn(dgPopularFAQs)
If rsc.SelectedIndexes.Length = 0 then
lblVoteResults.Text = "You did not select a FAQ!"
Else
Dim selIndex as Integer = rsc.SelectedIndexes(0)
lblVoteResults.Text = "You voted for item " & selIndex & _
", which is the FAQ with FAQID " & _
dgPopularFAQs.DataKeys(selIndex) & "