URGENT: Template Control always show empty value

A

Antonio

Hi,

I have been spending two full days to get this problem resolved but failed.
After successfully finding the label control, the Label.Text is always
having an empty string. But when the DataGrid finish rendered, all the
values are there, why??? Please refer to my code below:

Private Sub DataGrid_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles
DataGrid.ItemDataBound
Select Case e.Item.ItemType
Case ListItemType.Item, ListItemType.AlternatingItem

Dim lblCell As Label = CType(e.Item.Cells(2).FindControl("lblJan"), Label)

If CDbl(lblCell.Text.Trim) > 0 Then
lblCell.Text = ""
End If
End Select
End Sub

During the conversion to double, it get error because the text property is
having an empty string. But in actual fact, the final output to the cell is
6000. Why?? I just can't get the value populated! Can somebody help me pls?
Thanks!

Antonio



'For i = intJan To intDec

' intMth += 1

' Dim lblCell As New Label

' lblCell = CType(e.Item.Cells(i).FindControl("lbl" & MonthName(intMth,
True)), Label)

' If IsNumeric(lblCell.Text.Trim) Then

' lblCell.Text = Format(CDbl(lblCell.Text), "###,###,###,##0.00")

' If lblCell.Text.Trim = "-1.00" Then

' lblCell.Text = ""

' End If

' End If

'Next

End Select

End Sub
 
A

Antonio

Here you go...

WebForm.aspx:
:
<asp:TemplateColumn HeaderText="Jan">
<ItemTemplate>
<asp:Label ID="lblJan" Runat="server">
<%# DataBinder.Eval(Container.DataItem, "Jan") %>
</asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
:
WebForm.aspx.vb:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
'
' Code to get the DataTable goes here
'
DataGrid.DataSource = dtbDataTable
DataGrid.DataBind()
End If
End Sub

This problem happens during the first time the page is loaded (not during
postback). For you information, on the same ASPX where this DataGrid is
sitting on, contains a lot of User Controls. Could it be due to these User
Controls that screwed up the DataGrid's events life-cycle? However, the
ItemDatabound event managed to fire. Thanks.

Antonio
 
E

Elton Wang

Try

<asp:TemplateColumn HeaderText="Jan">
<ItemTemplate>
<asp:Label ID="lblJan" Runat="server" Text ='<%#
DataBinder.Eval(Container.DataItem, "Jan") %>' > </asp:Label>
</ItemTemplate>

HTH
 

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

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top