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

Reading the Multi selected Rows

4 Answers 125 Views
Grid
This is a migrated thread and some comments may be shown as answers.
o
Top achievements
Rank 2
o asked on 12 Aug 2009, 04:56 PM
Hi,

I am using RadGrid with Checkbox that i use to allow the user to select multi rows by checking the check box.

What i am facing is when i check the checkbox in the grid from top of the grid going down it works fine with me, i can later read all the selected rows nicely. But if i check the checkbox randomly top then button and then to, the reading will be incorrect. that means i can not get the selected rows correctly. So if i select 3 rows from button to up direction and try to read the selected rows, it return the
button row 3 times instead the value of the 3 row.

I hope i am making sense ....

I am using the following code.

Note Multi selection Server Side.

To Read the selected rows:

 

Protected Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click

 

 

        For Each dataItem As GridDataItem In RadGrid1.MasterTableView.Items

 

 

 

 

            If CType(dataItem.FindControl("CheckBox1"), CheckBox).Checked = True Then

 

     

 

              ListBox1.Items.Add(CType(RadGrid1.SelectedItems(0), GridDataItem)("ID").Text)

 

 

                  dataItem.Selected =

 

False

 

 

 

 

            End If

 

 

 

 

        Next

 

 

 

 

        For Each dataItem As GridDataItem In RadGrid1.MasterTableView.Items

 

 

 

 

            CType(dataItem.FindControl("CheckBox1"), CheckBox).Checked = False

 

 

 

 

        Next

 

 

 

 

End Sub

 

 

 

 

 




Protected

 

Sub RadGrid1_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadGrid1.PreRender

 

 

 

 

        For Each dataItem As GridDataItem In RadGrid1.MasterTableView.Items

 

 

 

 

           If CType(dataItem.FindControl("CheckBox1"), CheckBox).Checked = True Then

 

     

 

               dataItem.Selected = True

 

 

 

 

            End If    

 

 

 

 

       Next

 

 

 

 

End Sub

 

 

 

 

 

Hope some one will direct me to the right way of doing it.

Many Thanks
Omar

4 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 13 Aug 2009, 05:45 AM
Hi Omar,

Try the following code to get the selected rows and see whether it is working fine as you expected.

VB:
 
Protected Sub Button2_Click(ByVal sender As ObjectByVal e As EventArgs) 
    For Each dataItem As GridDataItem In RadGrid1.MasterTableView.Items 
        If DirectCast(dataItem.FindControl("CheckBox1"), CheckBox).Checked = True Then 
            ListBox1.Items.Add(DirectCast(dataItem("ID").Text, GridDataItem)
            dataItem.Selected = False 
        End If 
        ' Your Code for deselecting rows 
    Next 
End Sub 

-Shinu.
0
o
Top achievements
Rank 2
answered on 13 Aug 2009, 10:52 AM
Hi,

Thanks, it works fine now, but hay I have another Question for you, Please help on it.

I have template label in the grid, How to retrive the value of that template Label when the Itemcommand is triggered.

  </HeaderContextMenu>
                    <MasterTableView PageSize="10">
                        <Columns>
                            <telerik:GridTemplateColumn DataField="id" UniqueName="id" Visible="false">
                                <ItemTemplate>
                                    <asp:Label ID="Label35" runat="server" Text='<%# eval("id") %>'></asp:Label>
                                </ItemTemplate>
                            </telerik:GridTemplateColumn>

Now when the  ItemCommand is triggared I want to read the record Details, My problem is i do not know how to read the value of grid template label within my grid.

    Protected Sub Grid1_ItemCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles Grid1.ItemCommand
        clear("no")
        Dim sqlstr As String
        Dim dr As Data.SqlClient.SqlDataReader
        sqlstr = "select * from products where id='" & CType(e.FindControl("Label35"), Label).Text & "'"
        MsgBox(sqlstr)
        dr = ACCiMS_DB.Read_DR(sqlstr)
        While dr.Read
            txt_itemname.Text = dr("itemname")
            txt_itemNO.Text = dr("itemno")
            If dr("image") Is DBNull.Value Then
                GoTo l1
            End If
            Item_ImageBox.DataValue = dr("image")
l1:
        End While
        dr.Close()

    End Sub

    Please Help

0
Accepted
Princy
Top achievements
Rank 2
answered on 13 Aug 2009, 12:58 PM
Hi Omar,

Here is the sample code which explains how to access the text of a label placed inside the ItemTemplate of a GridTemplateColumn in the ItemCommand event.

VB:
 
  
 
    Protected Sub RadGrid1_ItemCommand(ByVal source As ObjectByVal e As GridCommandEventArgs) 
        If e.CommandName = "Select" Then 
                
            Dim strID As String = DirectCast(e.Item.FindControl("Label35"), Label).Text 
            
        End If 
    End Sub 
 
 


Regards
Princy
0
o
Top achievements
Rank 2
answered on 13 Aug 2009, 02:32 PM
Thanks,

Every thing is working very fine now. 

Thanks for the Help
Tags
Grid
Asked by
o
Top achievements
Rank 2
Answers by
Shinu
Top achievements
Rank 2
o
Top achievements
Rank 2
Princy
Top achievements
Rank 2
Share this question
or