473,666 Members | 2,368 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Creating Total Cell in DataGrid not working with Template Field

(Using C# 2.0)

Hi

I was trying to get a field formatted as currency, but could not do
this in my DataGrid unless I did the field as a template field.

However, when I try to create a total row when the row is databound, I
am just getting back that the value is a zerol length string -
presumably because my value is in a label.

How do I get around this? Given that unles the value is in the
template field, for some reason it won't write the £ sign out.

Many thanks

Darren
Source code:
<asp:TemplateFi eld HeaderText="£ Per Night">
<EditItemTempla te>
<asp:TextBox ID="TextBox1" runat="server" Text='<%#
Bind("PricePerN ight") %>'></asp:TextBox>
</EditItemTemplat e>
<ItemTemplate >
<asp:Label ID="Label1" runat="server" Text='<%#
Bind("PricePerN ight", "{0:c}") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateFie ld>
Code Behind:
protected void dgRoomBreakdown _ItemDatabound( object sender,
GridViewRowEven tArgs e)
{

switch (e.Row.RowType)
{
case DataControlRowT ype.DataRow:

if (e.Row.Cells[4].Text.Length > 0)
{
dPricePerNight +=
Double.Parse(e. Row.Cells[4].Text);
}
break;
case DataControlRowT ype.Footer:
e.Row.Cells[4].Text = dPricePerNight. ToString();
break;

}
}

Jun 9 '06 #1
1 1453
Fixed it myself!

You basically put the value into a text box (see code below) and then
do something like the following...

Daz

switch (e.Row.RowType)
{
case DataControlRowT ype.DataRow:
TextBox txtVal = (TextBox)(e.Row .Cells[4].Controls[1]);
if (txtVal.Text.Le ngth > 0)
{
dPricePerNight +=
Double.Parse(tx tVal.Text.Repla ce("£",""));
}
break;
case DataControlRowT ype.Footer:
e.Row.Cells[4].Text = dPricePerNight. ToString();
break;

}
}

Jun 9 '06 #2

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

Similar topics

1
1554
by: Maziar Aflatoun | last post by:
Hi, I have a datagrid which binds to a datareader dgXXXXX.DataSource = rdr; dgXXXXX.DataBind(); On dgXXXXX_EditCommand I can read the value of the selected row( e.Item.ItemIndex) which works. How can I read the contents of that cell. I have the following code which doesn't work.
0
1377
by: Joe Finsterwald | last post by:
Here is how to build a progress bar in dotnet that doesn't require any third party components and uses JavaScript on the client side so it doesn't require any additional post backs. This script works perfect for uploads, or any operation that requires a significant amount of processor time on the server. ------------------------------------------------------------------------------- In the header of your aspx page...
0
1528
by: MattB | last post by:
I got a response earlier, but I thought I'd bump this one to the top for a quick answer. Any tips, suggestions, or especially examples would be great! It seems like I may be able to do this with a simpler approach. Here's my current code for that column: <asp:TemplateColumn HeaderText="Item Description"> <ItemTemplate>
9
15011
by: Paul | last post by:
Hi I have a data grid with a hyperlink column. the colum has numbers like 00001,000002, ect. Just wondering how to get the text value of the cell as tempstring = datagrid.Items(rownumber).Cells.Item(column number).Text returns a blank string. It seems to work ok for the other columns that are just regular datagrid columns, not hyperlink types. Thanks. -- Paul G Software engineer.
9
2722
by: Lyners | last post by:
Quick question. I have some java script that looks like this; imgObj.parentNode.parentNode.childNodes(10).childNodes(0).value=imgObj.parentNode.parentNode.childNodes(6).innerText-imgObj.parentNode.parentNode.childNodes(9).childNodes(0).value This takes a cell in a datagrid (innertext) and subtracts the value of a text box (value) in another cell, then populates a second text box in a third cell with the value. it works except for the...
3
2439
by: Richard | last post by:
I'm trying to change a value of a cell based on another before the grid is displayed. I'm using the ItemDataBound event like this for a simple test: Select Case e.Item.ItemType Case ListItemType.Item, ListItemType.AlternatingItem If e.Item.Cells(7).Text = String.Empty Then e.Item.Cells(7).Text = "hello" End If End Select
2
11704
by: DraguVaso | last post by:
Hi, I'm looking for a nice way to format the cell of my datagrid according to some predefined 'rules'. I found a lot on the site of George shepherd, but it wasn't really what I was looking for: I found there: How can I change the font used in a Gridcell on a cell by cell or row by row basis. Wih this code I am able to change the Font/Background/... based on the position of the field (column and row). The problem is: it only changes...
2
1354
by: kito | last post by:
I have the following problem. I have a list of products in a Database. Now I would like to list them on a DataGrid, but in a special manner. In the first cell of a row in the DataGrid I would like to put the product-image (which is also not a problem) and in the second cell of the DataGrid I would like to put a Panel or something, where I add several things, like the title, description, price ... of the product and also controls such as...
3
2203
by: alan | last post by:
Hello all, I'd like to know if there is a nice method of defining a functor creator which accepts an N-ary function and returns a functor based on that function. For example I have a function: template<class X, class Y, class Z> X function(Y, Z); Passing it to the functor creator will give a functor equivalent to: template<class X, class Y, class Z>
0
8355
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8781
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8638
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7381
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6191
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4193
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2769
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2006
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1769
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.