Add formatted text to JavaScript function call during ItemDataBound of a Repeater Control.

B

Bryan

Hello,

I am taking values from a datatable and formatting them for use in a
JavaScript Function Call.
The end result is a mouse over tool tip.

Here is what I am doing.

I have tried to use a property but it uses the last set value of all.

Private Sub drTasks_ItemDataBound(ByVal sender As Object,
ByVal e As
System.Web.UI.WebControls.RepeaterItemEventArgs)
Handles
drTasks.ItemDataBound
If e.Item.ItemType = ListItemType.Item Then

Dim ttTitle As String = IIf(Not IsDBNull(e.Item.DataItem("Title")),
e.Item.DataItem("Title"), "")
Dim ttDesc As String = IIf(Not
IsDBNull(e.Item.DataItem("Description")), e.Item.DataItem("Description"),
"")
Dim ttDateStart As String = IIf(Not
IsDBNull(e.Item.DataItem("DateStart")),
CDate(e.Item.DataItem("DateStart")).ToShortDateString, "")
Dim ttDateDue As String = IIf(Not
IsDBNull(e.Item.DataItem("DateDue")),
CDate(e.Item.DataItem("DateDue")).ToShortDateString, "")

Dim ToolTip As New System.Text.StringBuilder

' First I build the text
ToolTip.Append("Title: " & ttTitle & "<br /><br />")
If ttDesc <> "" Then ToolTip.Append(ttDesc & "<br /><br />")
ToolTip.Append("Start Date: " & ttDateStart & "<br />Due Date: " &
ttDateDue)

' Once I have finished I push the value into the description.
e.Item.DataItem("Description") = ToolTip

End If
End Sub

On the HTML side I use the following in the <ItemTemplate> of the Repeater
Control.
...<td.... onMouseover="ddrivetip('<%#DataBinder.Eval(Container,
"DataItem.Description")%>','#284461', 300)">...

Any Iteas?

Thanks,
Bryan
 
A

Alvin Bruney [MVP]

try building the javascript embedded in the cell in the itemdatabound. Here
is some sample code.
e.Item.Cells[1].Attributes.Add("onmouseover","add your tooltip code here");
 
B

Bryan

Thanks for the tip.

I know that what you mentioned works with the datagrid control but it
doesn't work with the repeater control.
I will keep trying .

Thanks again,
Bryan

Alvin Bruney said:
try building the javascript embedded in the cell in the itemdatabound.
Here is some sample code.
e.Item.Cells[1].Attributes.Add("onmouseover","add your tooltip code
here");





--
Regards,
Alvin Bruney
[ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
Got tidbits? Get it here... http://tinyurl.com/27cok
Bryan said:
Hello,

I am taking values from a datatable and formatting them for use in a
JavaScript Function Call.
The end result is a mouse over tool tip.

Here is what I am doing.

I have tried to use a property but it uses the last set value of all.

Private Sub drTasks_ItemDataBound(ByVal sender As Object,
ByVal e As
System.Web.UI.WebControls.RepeaterItemEventArgs)
Handles
drTasks.ItemDataBound
If e.Item.ItemType = ListItemType.Item Then

Dim ttTitle As String = IIf(Not
IsDBNull(e.Item.DataItem("Title")), e.Item.DataItem("Title"), "")
Dim ttDesc As String = IIf(Not
IsDBNull(e.Item.DataItem("Description")), e.Item.DataItem("Description"),
"")
Dim ttDateStart As String = IIf(Not
IsDBNull(e.Item.DataItem("DateStart")),
CDate(e.Item.DataItem("DateStart")).ToShortDateString, "")
Dim ttDateDue As String = IIf(Not
IsDBNull(e.Item.DataItem("DateDue")),
CDate(e.Item.DataItem("DateDue")).ToShortDateString, "")

Dim ToolTip As New System.Text.StringBuilder

' First I build the text
ToolTip.Append("Title: " & ttTitle & "<br /><br />")
If ttDesc <> "" Then ToolTip.Append(ttDesc & "<br /><br />")
ToolTip.Append("Start Date: " & ttDateStart & "<br />Due Date: " &
ttDateDue)

' Once I have finished I push the value into the description.
e.Item.DataItem("Description") = ToolTip

End If
End Sub

On the HTML side I use the following in the <ItemTemplate> of the
Repeater Control.
...<td.... onMouseover="ddrivetip('<%#DataBinder.Eval(Container,
"DataItem.Description")%>','#284461', 300)">...

Any Iteas?

Thanks,
Bryan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top