473,408 Members | 2,839 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

label in footertemplate of datagrid

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?

Oct 1 '06 #1
7 2514
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]
<rn**@rediffmail.comwrote in message
news:11**********************@i3g2000cwc.googlegro ups.com...
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?

Oct 1 '06 #2
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]
<rn**@rediffmail.comwrote in message
news:11**********************@i3g2000cwc.googlegro ups.com...
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?
Oct 1 '06 #3
OK...Eliyahu...I got it...this is it...(for those who might find this
useful)

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

sqlReader = 'calling another function which returns
SqlDataReader

dlCart.DataSource = sqlReader
dlCart.DataBind
End Sub

Sub BindItem(ByVal obj As Object, ByVal ea As
DataListItemEventArgs)
Dim dblTotal As Double

dblTotal = 'calling a function which returns a Double

If (ea.Item.ItemType = ListItemType.Footer) Then
CType(ea.Item.FindControl("lblTotal"), Label).Text =
dblTotal
End If
End Sub
</script>

<form runat="server">
<asp:DataList ID="dlCart" OnItemDataBound="BindItem" 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>

Thanks, Eliyahu, for your useful suggestion...............:)

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]
<rn**@rediffmail.comwrote in message
news:11**********************@i3g2000cwc.googlegro ups.com...
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?
Oct 1 '06 #4
<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]
<rn**@rediffmail.comwrote in message
news:11**********************@h48g2000cwc.googlegr oups.com...
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]
<rn**@rediffmail.comwrote in message
news:11**********************@i3g2000cwc.googlegr oups.com...
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?

Oct 1 '06 #5
Eliyahu, can you please tell me why does ASP.NET throw the error

Name 'lblTotal' is not declared.

pointing to the

lblTotal.Text = dblTotal

line in the Page_Load sub when lblTotal is used within the
FooterTemplate of the DataList control?

Thanks
Eliyahu Goldin wrote:
<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]
<rn**@rediffmail.comwrote in message
news:11**********************@h48g2000cwc.googlegr oups.com...
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]
<rn**@rediffmail.comwrote in message
news:11**********************@i3g2000cwc.googlegro ups.com...
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?
Oct 1 '06 #6
You can't refer to controls in templates directly by their id.Only
FindControl in the item events will do.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
<rn**@rediffmail.comwrote in message
news:11********************@i3g2000cwc.googlegroup s.com...
Eliyahu, can you please tell me why does ASP.NET throw the error

Name 'lblTotal' is not declared.

pointing to the

lblTotal.Text = dblTotal

line in the Page_Load sub when lblTotal is used within the
FooterTemplate of the DataList control?

Thanks
Eliyahu Goldin wrote:
><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]
<rn**@rediffmail.comwrote in message
news:11**********************@h48g2000cwc.googleg roups.com...
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]
<rn**@rediffmail.comwrote in message
news:11**********************@i3g2000cwc.googlegr oups.com...
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?


Oct 3 '06 #7
But why can't controls be referred to by their IDs in templates?

Microsoft shouldn't have done this. It has made life all the more
tougher for ASP.NET developers.....
Eliyahu Goldin wrote:
You can't refer to controls in templates directly by their id.Only
FindControl in the item events will do.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
<rn**@rediffmail.comwrote in message
news:11********************@i3g2000cwc.googlegroup s.com...
Eliyahu, can you please tell me why does ASP.NET throw the error

Name 'lblTotal' is not declared.

pointing to the

lblTotal.Text = dblTotal

line in the Page_Load sub when lblTotal is used within the
FooterTemplate of the DataList control?

Thanks
Eliyahu Goldin wrote:
<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]
<rn**@rediffmail.comwrote in message
news:11**********************@h48g2000cwc.googlegr oups.com...
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]
<rn**@rediffmail.comwrote in message
news:11**********************@i3g2000cwc.googlegro ups.com...
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?
Oct 6 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: thejackofall | last post by:
I added a label server control in my aspx file. In the code behind, the IDE does not generate the corresponding object like it does with buttons and other objects. What am I doing wrong? Is...
1
by: Vishal | last post by:
Hello, I have a datagrid, which calculates the total in the footer. I am using public variables and simply appending the data to it. However the footertemplate is called twice and therefore it...
2
by: Will Chamberlain | last post by:
I have a footer template for adding items to a database. When 'Add' button is pressed the footer is displayed with textboxes for inserting data. There is 1 field that should not be tampered with...
1
by: sakieboy | last post by:
I have a FOOTERTEMPLATE that consists of a 3 DropDownLists. When something from DDL1 is selected it then populates DDL2, when something from DDL2 is selected it then populates DDL3. DDL1 is...
3
by: David C | last post by:
Here is my goal. I have a textbox in the FooterTemplate of a datagrid <FooterTemplate> <asp:TextBox ID="txtFooterTextBox" Runat="server"></asp:TextBox> </FooterTemplate> When the html is...
1
by: Groove | last post by:
I have a typical Repeater that contains a Template (html table). The repeater / template lists many records and in the footer, I'd like to simply SUM up the $$ amounts from all the records in the...
3
by: rockdale | last post by:
Hi, All: I have a datagrid with TemplateColumn as following: <asp:TemplateColumn Visible="False" > <ItemStyle Width="0px"></ItemStyle> <ItemTemplate> <asp:Label id="lblMin_Value"...
2
by: rn5a | last post by:
Consider the following code: <script runat="server"> Sub ShowData(obj As Object, ea As EventArgs) lblDate.Text = DateTime.Now.ToString("d") lblDate.DataBind() End Sub </script> <form...
0
by: rn5a | last post by:
One of the columns in a SQL Server 2005 DB table is named 'OrderDate' which stores the date & time on which an order has been placed. Since the 'OrderDate' of a particular order will be the same, I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.