This is a migrated thread and some comments may be shown as answers.

Get Values from radgrid including asp checkbox

2 Answers 231 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Carlos
Top achievements
Rank 1
Carlos asked on 06 Oct 2010, 05:16 PM
Hi, i got this radgrid, with 1 boundcolumn and some template columns (all chkbxs)...

<
telerik:RadGrid ID="rggrupos" DataSourceID="dsGrupos" runat="server"
           AutoGenerateColumns="False" GridLines="none">
            <MasterTableView Width="100%">
                <GroupByExpressions>
                    <telerik:GridGroupByExpression>
                        <SelectFields>
                            <telerik:GridGroupByField FieldAlias="Grupo" FieldName="grupo"></telerik:GridGroupByField>
                              
                        </SelectFields>
                        <GroupByFields>
                            <telerik:GridGroupByField FieldName="grupo" SortOrder="Ascending"></telerik:GridGroupByField>
                        </GroupByFields>
                    </telerik:GridGroupByExpression>
                </GroupByExpressions>
                <Columns>
                    <telerik:GridBoundColumn SortExpression="usuario" HeaderText="" HeaderButtonType="TextButton"
                        DataField="usuario">
                    </telerik:GridBoundColumn>
                    <telerik:GridTemplateColumn UniqueName="temprespseg"  HeaderText="RESPSEG"  >  
                                <ItemTemplate>  
                                    <asp:CheckBox ID="chkrespseg" runat="server" onclick="Check(this);"  />  
                                </ItemTemplate>  
                            </telerik:GridTemplateColumn
                            <telerik:GridTemplateColumn UniqueName="tempatender"  HeaderText="ATENDER"  >  
                                <ItemTemplate>  
                                    <asp:CheckBox ID="chkatender" runat="server" onclick="Check(this);"  />  
                                </ItemTemplate>  
                            </telerik:GridTemplateColumn
                            <telerik:GridTemplateColumn UniqueName="tempcomentar"  HeaderText="COMENTAR"  >  
                                <ItemTemplate>  
                                    <asp:CheckBox ID="chkcomentar" runat="server" onclick="Check(this);"  />  
                                </ItemTemplate>  
                            </telerik:GridTemplateColumn
                            <telerik:GridTemplateColumn UniqueName="tempenterar"  HeaderText="ENTERAR"  >  
                                <ItemTemplate>  
                                    <asp:CheckBox ID="chkenterar" runat="server" onclick="Check(this);"  />  
                                </ItemTemplate>  
                            </telerik:GridTemplateColumn
                            <telerik:GridTemplateColumn UniqueName="temparchivar"  HeaderText="ARCHIVAR"  >  
                                <ItemTemplate>  
                                    <asp:CheckBox ID="chkarchivar" runat="server" onclick="Check(this);"  />  
                                </ItemTemplate>  
                            </telerik:GridTemplateColumn
                             </Columns>
            </MasterTableView>
  
        </telerik:RadGrid>
What i need to to is to select (mark) some of the checkboxes on each row, and by clickin a button i want to know wich checkboxes are selected on each row, i identify each row by the first bound column (usuario)
btw, my code file is in vb

Thanks for your time.!

Carlos Nava

2 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 07 Oct 2010, 07:02 AM
Hello Carlos,

You can achieve this by looping through each GridDataItem and access each CheckBox using FindControl method. Then check whether these CheckBoxes are checked or not. Sample code is given below.

VB.NET:
Protected Sub Button1_Click(sender As Object, e As EventArgs)
    For Each item As GridDataItem In rggrupos.Items
        'loops through each grid item
        Dim chkname As String = ""
        Dim chk1 As CheckBox = DirectCast(item.FindControl("chkrespseg"), CheckBox)
        ' access first checkbox
        If chk1.Checked Then
                ' get the checkbox name if its checked
            chkname = TryCast(rggrupos.MasterTableView.GetColumn("temprespseg"), GridTemplateColumn).HeaderText
        End If
        Dim chk2 As CheckBox = DirectCast(item.FindControl("chkatender"), CheckBox)
        If chk2.Checked Then
            chkname += "," + TryCast(rggrupos.MasterTableView.GetColumn("tempatender"), GridTemplateColumn).HeaderText
        End If
        'similarly check all other checkboxes
        Response.Write(chkname)
        Response.Write("<br/>")
    Next
End Sub

Thanks,
Princy.
0
Carlos
Top achievements
Rank 1
answered on 07 Oct 2010, 05:12 PM
Hi Princy...
that code works like a charm...
thanks alot for your time and kindness
Here is the code i used, i just added the get username part, so i can get the value from a gridboundcolumn
Protected Sub btnturnar_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnturnar.Click
        For Each item As GridDataItem In rggrupos.MasterTableView.Items
            'loops through each grid item
            Dim chkname As String = ""
            Dim usuario As String = ""
            Dim chk1 As CheckBox = DirectCast(item.FindControl("chkrespseg"), CheckBox)
            ' get username
            usuario = item("usuario").Text
            ' access first checkbox
            If chk1.Checked Then
                ' get the checkbox name if its checked
                chkname = TryCast(rggrupos.MasterTableView.GetColumn("temprespseg"), GridTemplateColumn).HeaderText
            End If
            Dim chk2 As CheckBox = DirectCast(item.FindControl("chkatender"), CheckBox)
            If chk2.Checked Then
                chkname += "," + TryCast(rggrupos.MasterTableView.GetColumn("tempatender"), GridTemplateColumn).HeaderText
            End If
            'similarly check all other checkboxes 
            Response.Write(chkname)
            Response.Write("<br/>")
        Next
    End Sub

Thanks alot, and marked as Answer.

Carlos
Tags
Grid
Asked by
Carlos
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Carlos
Top achievements
Rank 1
Share this question
or