Re: DataGrid_ItemDataBound
I don't think there is a direct way of doing it as the DataGridItem is only going to store the data it needs and not necessarily the entire DataRow - depends how you've got the DataGrid setup.
Try setting up a DataKey for the DataGrid that is unique for each record and then you can grab this value in gdSearch_ItemDataBound and lookup the unique value in the DataTable to get the DataRow.
Hope that makes sense.
DJ
Re: DataGrid_ItemDataBound
Cheers. I have found a method, which works, and was just about to post it when u replied.
I came up with:
VB Code:
Private Sub gdSearch_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles gdSearch.ItemDataBound
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
Dim DataItem As DataGridItem = DirectCast(e.Item, DataGridItem)
Dim dr As DataRowView = DirectCast(DataItem.DataItem, DataRowView)
Dim AssetKey As Integer = DirectCast(dr.Row.Item("AssetKey"), Integer)
Dim DateFrom As Date = DirectCast(dr.Row.Item("DateFrom"), Date)
Dim DateTo As Date = DirectCast(dr.Row.Item("DateTo"), Date)
Dim Text As String = DateFrom.ToString("ddd dd MMM yyyy HH:mm") & " - " & DateTo.ToString("HH:mm")
Dim URL As String = "Javascript:openEditDialog("
URL &= AssetKey & ", 0"
URL &= ", " & ((CType(DateFrom.ToString("HH"), Integer) * 60 + CType(DateFrom.ToString("mm"), Integer)) / 15).ToString
URL &= ", " & ((CType(DateTo.ToString("HH"), Integer) * 60 + CType(DateTo.ToString("mm"), Integer)) / 15).ToString
URL &= ", '" & DateFrom.ToString("dd/MMM/yyyy") & "'"
URL &= ", 0)"
Dim lnk As HyperLink = DirectCast(DataItem.FindControl("lnkDetails"), HyperLink)
lnk.Text = Text
lnk.NavigateUrl = URL
End If
End Sub
The main 2 lines refering to the thread subject are:
VB Code:
Dim DataItem As DataGridItem = DirectCast(e.Item, DataGridItem)
Dim dr As DataRowView = DirectCast(DataItem.DataItem, DataRowView)
What do you think?
Woka
Re: DataGrid_ItemDataBound
I have one other quick q. though.
In the status bar in IE is shows "Javascript:openEditDialog(Blah blah blah)"
How can I change this to "Create Booking" what is the property of the hyper link control that needs to be changed?
Woof
Re: DataGrid_ItemDataBound
Well you learn a new thing everyday! *Stores in recesses of mind*
DJ
Re: DataGrid_ItemDataBound
Quote:
How can I change this to "Create Booking" what is the property of the hyper link control that needs to be changed?
Add the following javascript in <a href tag
onmouseover="javascript:window.status='Create Booking';"
Re: DataGrid_ItemDataBound
hi, that doesn't seem to work :(
Whe I leave the hyperlinks then the status shows "Create Booking", but when I roll my mouse over the links then the status windows changes to Javascript: balh blah blah.
Woof
Re: DataGrid_ItemDataBound
You got the JS working now?
Re: DataGrid_ItemDataBound
Re: DataGrid_ItemDataBound
For the status script to work you should put your javascript in the onclick attribute for the href and leave the url as "#". Also use onmouseout to reset the status back to Empty string.
Re: DataGrid_ItemDataBound
Going over this thread, there was a simpler method to get the datarow in the ItemDataBound. Access the row number in your table (in your dataset) using e.Item.Itemindex.
Re: DataGrid_ItemDataBound
Yea, but I don't have the datatable. I am not storing it as a modular level varible.
I set the datasource, the GC deals with the temp dt I created.
Woka