473,394 Members | 1,674 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,394 software developers and data experts.

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:TemplateField HeaderText="£ Per Night">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%#
Bind("PricePerNight") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%#
Bind("PricePerNight", "{0:c}") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
Code Behind:
protected void dgRoomBreakdown_ItemDatabound(object sender,
GridViewRowEventArgs e)
{

switch (e.Row.RowType)
{
case DataControlRowType.DataRow:

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

}
}

Jun 9 '06 #1
1 1447
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 DataControlRowType.DataRow:
TextBox txtVal = (TextBox)(e.Row.Cells[4].Controls[1]);
if (txtVal.Text.Length > 0)
{
dPricePerNight +=
Double.Parse(txtVal.Text.Replace("£",""));
}
break;
case DataControlRowType.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
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...
0
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...
0
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...
9
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 =...
9
by: Lyners | last post by:
Quick question. I have some java script that looks like this; ...
3
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...
2
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:...
2
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...
3
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:...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.