|
-
Aug 19th, 2005, 03:21 AM
#1
DataGrid_ItemDataBound
I have the following code.
VB Code:
Public Sub GetData()
Dim dt As DataTable = 'code to create datatable.
gdSearch.DataSource = dt
gdSearch.DataBind()
End Sub
Private Sub gdSearch_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles gdSearch.ItemDataBound
Dim DataItem As DataGridItem
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
DataItem = CType(e.Item, DataGridItem)
'Code to populate row
End If
End Sub
On the item bound how can I get hold of the DataRow that is used to populate this DataGridItem?
Woof
-
Aug 19th, 2005, 04:05 AM
#2
Frenzied Member
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
If I have been helpful please rate my post. If I haven't tell me!
-
Aug 19th, 2005, 04:08 AM
#3
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
-
Aug 19th, 2005, 04:11 AM
#4
Re: DataGrid_ItemDataBound
I have one other quick q. though.
In the status bar in IE is shows "Javascript penEditDialog(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
-
Aug 19th, 2005, 04:12 AM
#5
Frenzied Member
Re: DataGrid_ItemDataBound
Well you learn a new thing everyday! *Stores in recesses of mind*
DJ
If I have been helpful please rate my post. If I haven't tell me!
-
Aug 19th, 2005, 10:57 AM
#6
PowerPoster
Re: DataGrid_ItemDataBound
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';"
-
Aug 31st, 2005, 05:10 AM
#7
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
-
Aug 31st, 2005, 06:26 AM
#8
Re: DataGrid_ItemDataBound
You got the JS working now?
-
Oct 12th, 2005, 11:56 AM
#9
Re: DataGrid_ItemDataBound
-
Oct 14th, 2005, 02:26 AM
#10
New Member
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.
Just because you're paranoid doesn't mean they aren't out to get you
Quidquid latine dictum sit, altum viditur
-
Oct 14th, 2005, 05:04 AM
#11
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.
-
Oct 14th, 2005, 05:06 AM
#12
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|