Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB ASP.NET Datagrid Editing

Status
Not open for further replies.

johnpienaar

Technical User
Jun 23, 2004
18
0
0
ZA
Hi
I am fairly new at VB and ASP.NET and have been trying to edit items on a grid. I have managed to create editable columns or editable rows, but I cannot control it any further than that. What I am trying to do is the following:
For example say we have a 10 column by 10 row grid. I would like to make columns 5-10 editable but only for rows 3-7.
Is this possible with the standard Visual Studio datagrid? - I am using Visual Studio 2003.
If not are there any downloadable grids that can do this that are either free or inexpensive?
Any insight/help would be appreciated.
 
if you know specific consistent data that could identify if its editable or not, ie column 3 says "bla bla", then you could use the onItemDataBound event.

Code:
'HTML
<asp:DataGrid id=datagrid runat=server onItemDataBound=datagrid_IDB>
...
</asp:DataGrid>

'Code
Sub datagrid_IDB(sender As Object, e As DataGridItemEventArgs)
        Select Case e.Item.ItemType
            Case ListItemType.Item, ListItemType.AlternatingItem
                'This would be your edit button if its in column 0              
                Dim button As LinkButton = CType(e.Item.Cells(0).Controls(0), LinkButton)
                If e.Item.cells(2).Text = "Bla Bla" Then
                    button.visible = True
                Else
                    button.visible = False
                End If
        End Select
End Sub

If you use ItemTemplates you might have to do...

Sub datagrid_IDB(sender As Object, e As DataGridItemEventArgs)
        Select Case e.Item.ItemType
            Case ListItemType.Item, ListItemType.AlternatingItem
                'This would be your edit button if its in column 0              
                Dim button As LinkButton = CType(e.Item.Cells(0).Controls(0), LinkButton)
                If CType(e.Item.FindControl("txtLabel"),Label).Text = "Bla Bla" Then
                    button.visible = True
                Else
                    button.visible = False
                End If
        End Select
End Sub
 
Thanks to both of you for your help- much appreciated.
I've managed to get it working. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top