Re: label in footertemplate of datagrid



<asp:DataList ID="dlCart" runat="server"
OnItemDataBound="dlCart_ItemDataBound">

In the script:

Sub dlCart_ItemDataBound(sender As Object, e As DataListItemEventArgs)
If e.Item.ItemType = ListItemType.Footer
Dim dblTotal As Double
dblTotal = 'calling a function which returns a Double
Dim TotalLabel As Label = CType(e.Item.FindControl("lblTotal"),
Label)
TotalLabel .Text = dblTotal
End If
End Sub


--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


<rn5a@xxxxxxxxxxxxxx> wrote in message
news:1159698485.717845.280120@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Eliyahu, could you please show me a small example of what you have
suggested? I haven't done anything like that anytime.

Eliyahu Goldin wrote:
Handle ItemDataBound event. Detect the footer item by the ItemType. Use
FindControl ("lblTotal") to locate the label inside the footer item.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


<rn5a@xxxxxxxxxxxxxx> wrote in message
news:1159696793.107694.146910@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
How can I place a Label control in the FooterTemplate of a DataList
control?

I tried this

<script runat="server">
Sub Page_Load(obj As Object, ea As EventArgs)
Dim dblTotal As Double
Dim sqlReader As SqlDataReader

dblTotal = 'calling a function which returns a Double
sqlReader = 'calling another function which returns
SqlDataReader

dlCart.DataSource = sqlReader
dlCart.DataBind
lblTotal.Text = dblTotal
End Sub
</script>

<form runat="server">
<asp:DataList ID="dlCart" runat="server">
<HeaderTemplate>
<table>
<th>ID</th>
<th>Product</th>
<th>Unit Price</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
........
</tr>
</ItemTemplate>
<FooterTemplate>
<tr>
<td colspan=2>TOTAL:</td>
<td><asp:Label ID="lblTotal" runat="server"/></td>
</tr>
</table>
</FooterTemplate>
</asp:DataList>
</form>

But it throws the error

Name 'lblTotal' is not declared.

pointing to

lblTotal.Text = dblTotal

How do I add a Label within the FooterTemplate of a DataList so that
the total can be displayed under the Unit Price column? Or is there any
other way by which I can display the total under the Unit Price column
in the DataList?




.



Relevant Pages

  • RE: Halt code without resetting
    ... Public Sub MainSub() ... ' Continue with other processing in this routine ... Private Function SubFunction1() As fnReturnValues ... ' Stop processing in this function and stop processing by calling ...
    (microsoft.public.access.modulesdaovba)
  • Re: Adding dropdownlist to a datalist
    ... "Karl" wrote: ... > ItemDataBound isn't invoked on postback because the control isn't databound ... > Private Sub List_ItemDataBound(ByVal sender As Object, ... > DataListItemEventArgs) Handles list.ItemDataBound ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: CheckBoxList in DataList Question?
    ... AddHandler cblGroups.SelectedIndexChanged, AddressOf ... >> Public Sub Item_Created(ByVal sender As Object, ... >> DataListItemEventArgs) Handles DataList1.ItemDataBound ... >> AddHandler cblGroups.SelectedIndexChanged, AddressOf Check_Clicked ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Event enqueing in PostMessage style
    ... >> invoked not earlier as the calling thread returns to the central message ... >> meaning that the event handler is called immediately and interrupts the ... >> Private WithEvents MyEventObj As New MyEventClass ... >> Private Sub MyHandler() Handles MyEventObj.MyEvent ...
    (microsoft.public.dotnet.general)
  • Re: late binding
    ... If the method from objvar.PerformsomeAction is calling the GC or by instance ... than it works in my opinion. ... Dim objVar as new foo ... End Sub ...
    (microsoft.public.dotnet.languages.vb)