Error msg prompt when check for the userId and display the linkbutton in datagrid.

tiffany

Well-known member
Joined
Aug 7, 2005
Messages
57
Programming Experience
1-3
Hi, i have this idea on the codes to check whether the userID is match with teh userID in the datagrid. If it is match, the linkbutton in datagrid visibility is true. Else false. But for the following codes, i try doing it when hte userID is match, the button visibility will be false.


Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid1.ItemDataBound


Dim vUID As String = Session("memberID")
Dim DUID As String = e.Item.Cells(1).Text
Dim l As LinkButton

'the linkbutton is located in the col 6
l = e.Item.Cells(6).Controls(0)

If DUID = vUID Then
l.Visible = False

End If


When i first try it out, it turns out prefectly fine when the visisbility turn false. However, after i try playing around with the codes, it give me an error msg: Specified argument was out of the range of valid values. Parameter name: index in this line : l = e.Item.Cells(6).Controls(0)



Can anyone please help me with it?
Thankx
tiffany

 
I think this is what is happening: when you nest controls inside of a datagrid, they have to be re-created/re-bound to the grid every time the page loads, including across a postback. When you access Control 0 in cell 6 after the postback, there is probably no control in that cell, so you get the index out of range because 0 is outside the range of the e.item.cells(6).controls count.
 
Back
Top