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

RowCreated event so multiselect checkbox can be suppressed

2 Answers 47 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Robert Vreeland
Top achievements
Rank 1
Robert Vreeland asked on 25 Feb 2009, 12:16 AM

in a grid with multiselection turned on, I'd like to be able to examine the underlying data row when each row is being created so I can decide whether or not I want that row in the table to be selectable or not (i.e. whether to show the checkbox on the far left for selection).

With the normal datagrid I could use code such as the below to examine each row as it was being created.  How do I do this with the radgrid?

 

Private

Sub MyOnItemCreated(ByVal sender As Object, ByVal e As GridViewRowEventArgs) Handles dgmain.RowCreated

 

 

Dim status As String

 

 

 

 

Dim flockId As String

 

 

 

 

Dim requesterEmail As String

 

 

 

 

If (Not (e.Row.DataItem Is Nothing)) Then

 

 

 

flockId = DataBinder.Eval(e.Row.DataItem,

"flockid").ToString

 

status = DataBinder.Eval(e.Row.DataItem,

"status").ToString

 

requesterEmail = DataBinder.Eval(e.Row.DataItem,

"requesteremail").ToString

 

 

If (e.Row.RowType = DataControlRowType.DataRow) Then

 

 

 

 

If ((status = "P") AndAlso (requesterEmail = CustomPrincipal.UserEmail OrElse User.IsInRole("dms") OrElse User.IsInRole("tms"))) Then

 

 

 

sbAll +=

"document.aspnetForm.cxitem" + flockId + ".checked=true;" + Chr(10)

 

sbNone +=

"document.aspnetForm.cxitem" + flockId + ".checked=false;" + Chr(10)

 

 

End If

 

 

 

 

End If

 

 

 

 

End If

 

 

 

 

End Sub

 

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 25 Feb 2009, 06:32 AM
Hello Robert,

In RadGrid Control, the RowCreated event of GridView is replaced by ItemCreated event and a DataRow is accessed as GridDataItem. So you can try replacing your code with the following to examine your rows:
cs:
 Protected Sub RadGrid1_ItemCreated(ByVal sender As Object, ByVal e As GridItemEventArgs) 
         Dim status As String = Nothing 
         Dim flockId As String = Nothing 
         Dim requesterEmail As String = Nothing 
         
         If ((e.Item.DataItem IsNot Nothing)) Then 
             flockId = DataBinder.Eval(e.Item.DataItem, "flockid").ToString() 
             status = DataBinder.Eval(e.Item.DataItem, "status").ToString() 
             requesterEmail = DataBinder.Eval(e.Item.DataItem, "requesteremail").ToString() 
             
             If (TypeOf e.Item Is GridDataItem) Then 
                 If ((status = "P") AndAlso (requesterEmail = CustomPrincipal.UserEmail OrElse User.IsInRole("dms") OrElse User.IsInRole("tms"))) Then 
                     
                     sbAll += ("document.aspnetForm.cxitem" & flockId & ".checked=true;") + Strings.Chr(10) 
                     sbNone += ("document.aspnetForm.cxitem" & flockId & ".checked=false;") + Strings.Chr(10) 
                 End If 
             End If 
         End If 
     End Sub 
 

Thanks
Princy.
0
Robert Vreeland
Top achievements
Rank 1
answered on 25 Feb 2009, 09:22 PM
Thanks.  That left me with the below.  

 

        Public Sub dgmain_ItemCreated(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles dgmain.ItemCreated  
            Dim status As String = Nothing 
            Dim requesterEmail As String = Nothing 
 
            If (e.Item.DataItem IsNot Nothing) Then  
                status = DataBinder.Eval(e.Item.DataItem, "status").ToString()  
                requesterEmail = DataBinder.Eval(e.Item.DataItem, "requesteremail").ToString()  
 
                If (TypeOf e.Item Is Telerik.Web.UI.GridDataItem) Then  
                    If Not ((status = "P") AndAlso (requesterEmail = CustomPrincipal.UserEmail OrElse User.IsInRole("dms") OrElse User.IsInRole("tms"))) Then  
                        'CType(e.Item,Telerik.Web.UI.GridDataItem).  
                    End If  
                End If  
            End If  
        End Sub 

I was hoping however that there would be an easy way, such as a "canbeselected" property I could then set on the griddataitem so I could make it not be selectable.  However I haven't found any obvious way to do so.

Is there a way to do this on a row by row basis?

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