Geekpedia Programming Tutorials






How To Add Calculated Columns To A GridView?

On Tuesday, July 22nd 2008 at 11:09 AM
By SammyBar
Hi,

I'm trying to display a DataSet data by using a GridView control on Visual
Studio 2005 professional. I'm displaying the DataSet directly, without using
the DataSource object. I can display selected columns from my DataSet, but I
need to display a grid column wich is the result of manipulating some
DataSet columns.
Obviously I can make the DataSet's table to include the needed column
precalculated and filled. But it means to couple the dataset to the grid
needs and I'd prefer to mantain the DataSet independent of the presentation
layer.
How can I do that?

Any hint is welcomed
Thanks in advance
Sammy

Re: How to add calculated columns to a GridView?

by Eliyahu Goldin on Wednesday, July 23rd 2008 at 09:23 AM
Why don't you make a template column and fill it in the RowDataBound event?

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net


"SammyBar" <sammybar@gmail.com> wrote in message
news:uEeRrzA7IHA.616@TK2MSFTNGP02.phx.gbl...
> Hi,
>
> I'm trying to display a DataSet data by using a GridView control on Visual
> Studio 2005 professional. I'm displaying the DataSet directly, without
> using the DataSource object. I can display selected columns from my
> DataSet, but I need to display a grid column wich is the result of
> manipulating some DataSet columns.
> Obviously I can make the DataSet's table to include the needed column
> precalculated and filled. But it means to couple the dataset to the grid
> needs and I'd prefer to mantain the DataSet independent of the
> presentation layer.
> How can I do that?
>
> Any hint is welcomed
> Thanks in advance
> Sammy
>
>

Re: How to add calculated columns to a GridView?

by Stan on Thursday, July 24th 2008 at 10:35 PM
On 22 Jul, 16:09, "SammyBar" <sammy...@gmail.com> wrote:
> Hi,
>
> I'm trying to display a DataSet data by using a GridView control on Visual
> Studio 2005 professional. I'm displaying the DataSet directly, without using
> the DataSource object. I can display selected columns from my DataSet, but I
> need to display a grid column wich is the result of manipulating some
> DataSet columns.
> Obviously I can make the DataSet's table to include the needed column
> precalculated and filled. But it means to couple the dataset to the grid
> needs and I'd prefer to mantain the DataSet independent of the presentation
> layer.
> How can I do that?
>
> Any hint is welcomed
> Thanks in advance
> Sammy

With templated columns you can bind data using an expression that does
the computation. For example:

<asp:Label ID="IncPriceLabel" runat="server" Text = '<%#
(double)Eval("price") * 1.175 %>' />

HTH
Latest Tech Bargains

Advertisement

Free Magazine Subscriptions

Today's Pictures

Today's Video

Other Resources

Latest Download

Latest Icons