Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

GridView basics

0 views
Skip to first unread message

Peter Laman

unread,
Aug 28, 2008, 6:47:42 AM8/28/08
to
Hello, here are some basic GridView questions. I'm using a GridView in
Visual Web Developer to display data from an SQLServer database. I use
C# as programming language.

- How can I format the text in a column. I'm looking for some event
handler that takes the value from the database and formats it for
rendering it on the webpage. Is using a TemplateField the right
direction?
- Some columns in the query contain codes that should be looked up in
lookup tables. I don't want to join all of those tables in the query,
but look them up at display time and render the description in stead
of the code. Is there a typical precooked way to do this?

Eliyahu Goldin

unread,
Aug 31, 2008, 8:56:30 AM8/31/08
to
RowDataBound event is good for formatting.You can format based either on the
output text (e.Row.Cells collection) or on the data as they come from
database (e.Row.DataItem). In the latter case you need to typecast the data
item to the correct class.

I would prefer to join the tables in the same select statement, even if you
end up with a bulky sql.

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


"Peter Laman" <peter...@gmail.com> wrote in message
news:4c9b73dd-513d-41ac...@k30g2000hse.googlegroups.com...

Peter Laman

unread,
Sep 2, 2008, 10:52:35 AM9/2/08
to
Thank you, Eliyahu. I tried using e.Row.DataItem.ItemArray. The value
I must format is e.Row.DataItem.ItemArray[7], which should be a
floating point number - it is in the SQL server database, but if I try
to assign it to a variable of type double, it compiles right, but in
the browser I get a type cast error. I'm new to C# (not to
programming), but what am I doing wrong?

Peter

On 31 aug, 14:56, "Eliyahu Goldin"


<REMOVEALLCAPITALSeEgGoldD...@mMvVpPsS.org> wrote:
> RowDataBound event is good for formatting.You can format based either on the
> output text (e.Row.Cells collection) or on the data as they come from
> database (e.Row.DataItem). In the latter case you need to typecast the data
> item to the correct class.
>
> I would prefer to join the tables in the same select statement, even if you
> end up with a bulky sql.
>
> --
> Eliyahu Goldin,
> Software Developer
> Microsoft MVP [ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net
>

> "Peter Laman" <peter.la...@gmail.com> wrote in message

Eliyahu Goldin

unread,
Sep 2, 2008, 11:15:50 AM9/2/08
to
Try Convert.ToDouble(e.Row.DataItem.ItemArray[7])

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

http://msmvps.com/blogs/egoldin
http://usableasp.net


"Peter Laman" <peter...@gmail.com> wrote in message

news:ccd3402e-4734-4989...@m36g2000hse.googlegroups.com...

0 new messages