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

[Solved] Selecting a Row in ItemCreated

1 Answer 92 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kenyon Fox
Top achievements
Rank 1
Kenyon Fox asked on 08 Apr 2009, 04:37 PM
I am attempting to select a specific row in my grid in the ItemCreated event handler and am getting an "ArgumentOutOfRangeException" when the selection code is executed.

Following is my code:

Protected Sub radGridProspects_ItemCreated(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles radGridProspects.ItemCreated  
        If TypeOf e.Item Is GridDataItem Then  
            Dim editLink As HyperLink = DirectCast(e.Item.FindControl("EditLink"), HyperLink)  
            editLink.Attributes("href") = "#"  
            editLink.Attributes("onclick") = [String].Format("return ShowEditProspectWindow('{0}','{1}');", e.Item.OwnerTableView.DataKeyValues(e.Item.ItemIndex)("ProspectID"), e.Item.ItemIndex)  
 
            If e.Item.OwnerTableView.DataKeyValues(e.Item.ItemIndex)("ProspectID") = Session("ProspectID") Then  
                e.Item.Selected = True 
            End If  
        End If  
    End Sub 

I don't seem to run into any problems with the if statement being evaluated properly on line 7 because it enters the if statement without issue.  I get the error when it attempts to set the selected attribute to true on line 8.  I must be missing something...any help would be appreciated.

Regards,
Kenyon

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 09 Apr 2009, 06:47 AM
Hello Kenyon,

Try adding the second half of your code in the ItemDataBound event of your grid as shown below and see if it helps:
C#:
Protected Sub radGridProspects_ItemDataBound(sender As Object, e As GridItemEventArgs) 
    If TypeOf e.Item Is GridDataItem Then 
 
        Dim item As GridDataItem = DirectCast(e.Item, GridDataItem) 
        If item.OwnerTableView.DataKeyValues(e.Item.ItemIndex)("ProspectID") = Session("ProspectID"Then 
            item.Selected = True 
        End If 
    End If 
 
End Sub 

Thanks
Princy.
Tags
Grid
Asked by
Kenyon Fox
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or