radio button inside datagrid
Hi
I have used radio button inside datagrid. It is allowing me to select all
the radio buttons. Actually only one radio button should be selected at a
time, on selecting other radio button, previous radio button should be
unchecked. I am not able to call onclick event of that radio button.
Hope some one would already solved this kind of problem.
Thanks
Balaji
Radio button as template column in datagird
-----This is Datagrid with a button just copy this into u r aspx page----
<asp:datagrid id="grdReport" style="Z-INDEX: 101; LEFT: 48px; POSITION: absolute; TOP: 200px"
runat="server" Width="144px" BackColor="White" AutoGenerateColumns="False" CellPadding="4"
Height="22px" BorderWidth="1px" BorderStyle="None" BorderColor="#CC9966">
<Columns>
<asp:BoundColumn DataField="type" SortExpression="type" HeaderText="Type"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="Select">
<ItemTemplate>
<asp:RadioButton id="rdbBatchTime" runat="server" AutoPostBack="True" OnCheckedChanged="SelectOnlyOne"></asp:RadioButton>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>
<asp:button id="Button1" style="Z-INDEX: 102; LEFT: 336px; POSITION: absolute; TOP: 40px" runat="server"
Text="Display Selected Value"></asp:button>
-----This is Code Bloack just copy this into u r code page , then see the result and chage it to ur needs----
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim m_ClientID As String = ""
Dim rb As RadioButton
Dim j As Integer = 1
For Each i As DataGridItem In grdReport.Items
rb = CType(i.FindControl("rdbBatchTime"), RadioButton)
If rb.Checked = True Then
Response.Write(j)
End If
j += 1
Next
End Sub
Public Sub SelectOnlyOne(ByVal sender As Object, ByVal e As System.EventArgs)
Dim m_ClientID As String = ""
Dim rb As New RadioButton
rb = CType(sender, RadioButton)
m_ClientID = rb.ClientID
For Each i As DataGridItem In grdReport.Items
rb = CType(i.FindControl("rdbBatchTime"), RadioButton)
rb.Checked = False
If (m_ClientID = rb.ClientID) Then
rb.Checked = True
End If
Next
End Sub