Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Gridview Formatting

Status
Not open for further replies.

jcs1953

IS-IT--Management
Nov 28, 2007
53
US
I'm using Visual Web Developer 2005 Express with VB.
I have a query that returns something like this:

test_date test_name result
12/12/2006 AST 10.23
01/10/2007 AST 12.20
12/12/2006 BUN 2.00
12/12/2006 GTR 19.20
01/10/2007 GTR 18.30
and so on ...

I want to display the results in a read only gridview like this:
test_name 12/12/2006 01/10/2007
AST 10.23 12.20
BUN 2.00
GTR 19.20 18.30

Suggestions on how to do this would be great.
Is it possible to dynamically set the formatting of the gridview in code-behind. In other words can I have just one gridview but any number of queries called by user input (textbox, dropdown list etc.)?
I've tried researching formatting gridview but haven't found much for code-behind. Do you know where I can find more info on this? A simple gridview.something does this would be big help.
Thanks
 
The best way to handle this is by working with your query. there are a lot of tutorials out there. just do search on pivoting..
 
As taree says, this is really an issue that should be delt with in SQL. If you are using SQl Server 2005, thrre is a Pivot operator.
 
OK. I'll do some research on the Pivot operator. What about dynamically setting the formatting like cell spacing in code-behind (is that what it's called)?
 
i would handle presentation concerns at the html level and use a js library like jquery to handle DOM manipulation. treat the code behind as a connector to get data to the html. I would discourage the use of the code behind to heavily manipulate the DOM.

some objects (int, long, datetime, etc) have ToString() overrides which allow you to format the string for viewing. this is useful when presenting the data.

DateTime.Now.ToString("MM-dd-yy HH:mm:ss");
will produce
05-13-09 10:52:33

one final note. since your data is readonly. use a repeater instead of a gridview to build the html. Gridviews are only good for inline editing. which, I believe, should be avoided as well.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Let me throw one more requirement into the mix. I actually have 2 databases that I need to retrieve data from ... SQL Server 2005 Express and Oracle 10g Express. The way I have been doing this is to run 2 separate queries, put the results into datatables and then sort like this:

Dim mytable1 As DataTable
mytable1 = DAL.GetSQLSedrateResults(TBPID.Text)
Dim dr As New DataTableReader(mytable1)
mytable1.Load(dr)

Dim dv As DataView = mytable1.DefaultView
dv.Sort = "Run_Date DESC"



Dim mytable2 As DataTable
mytable2 = DAL.GetOracleSedrateResults(TBPID.Text)
Dim dr2 As New DataTableReader(mytable2)
mytable1.Load(dr2)
Dim dv1 As DataView = mytable1.DefaultView
dv1.Sort = "RUN_DATE DESC"

Will I be able to incorporate Pivot into this?
 
Not what I mentioned. In this case you will have to pivot the data yourself in the code-behind unless you use a linked server to get the data and use a SP to pivot the data.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top