roshen
April 10th, 2003, 05:54 AM
I have bound data to a DataGrid, which has ID, name, address columns. But I want the key field (for example ID) as a href so that by clicking on the ID, I can take the user to another page where I can let him edit that record.
I want to point out that I dont want to edit the data in the datagrid itself. If possible please give me some links to tutorials associated with the stuff
:confused:
hellomadhu
April 10th, 2003, 06:33 AM
if u dont want to edit, why dont u display the data in a table instead of a datagrid so that things would be easier.
i dont think datagrid has the capablity to display hyperlinks.
gknierim
April 12th, 2003, 03:53 PM
roshen,
Datagrids do have the capability to display pretty much any object that is available : hyperlinks, text, dropdowns, images, buttons, etc.
To display a link in your datagrid that the user can click on, click on your datagrid, then in the properties go to the columns property and then go into the collection (...). The datagrid properties window will appear. On the left hand side, select Columns from the list and you will see 2 lists. Available columns and Selected columns. You will need to a Button-Select column to the selected columns list. Then in the remaining boxes below, select LinkButton for the button type.
Once all that is done, you will use the ItemCommand method of the datagrid to determine what to do when the Id is clicked. Here is the ItemCommand code that I use to display a panel of textboxes when I want to update a row in my grid instead of allowing them to edit the grid:
Private Sub dgDetail_ItemCommand(ByVal source As Object, _
ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dgDetail.ItemCommand
' All commands first go through the ItemCommand handler. Thus, if the user
' clicks a header to sort a field, or a paging control to page through
' the results, exit immediately as code for these items is in the
' SortCommand And PageIndexChanged event handlers, respectively.
If e.Item.ItemType = ListItemType.Pager Or _
e.Item.ItemType = ListItemType.Header Then Exit Sub
' To figure out which Button was clicked, cast the CommandSource property
' of the DataGridCommandEventArg "e".
Dim btn As LinkButton = CType(e.CommandSource, LinkButton)
If btn.Text = "Edit" Then
GetAClient(CLng(e.Item.Cells(9).Text))
Else ' Delete the product.
' Use the DataKeys collection to access the key values of each record
' (displayed as a datarow) in a data listing control. This allows you to
' store the key field with a data listing control without displaying it in
' the control. This collection is automatically filled with the values from
' the field specified by the DataKeyField property. You can set this on
' the .aspx page or programmatically, as was done in this sample in the
' BindProductsGrid method.
'
' The ItemIndex property contains the 0-based datarow index for the
' DataGridItem. Items that are not datarows have an ItemIndex = -1 (a standard
' ASP .NET value indicating that an item is not selected--e.g., to determine
' if the user checked a box in a CheckBoxList control, you could check to see
' if the value SelectedIndex property was > -1.)
DeleteItem(dgDetail.DataKeys(e.Item.ItemIndex).ToString)
End If
End Sub
Hope this gets you started in the right direction. There are tons of examples of how to do this very thing all over the web. Please do a search for them and then will have more detail.
Greg