472,139 Members | 1,437 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,139 software developers and data experts.

GridView help required

I have a GridView control which is bound to a Stored Procedure (SP) using a
SQLDataSource. The problem I'm having is that the SP returns 4 known columns
and x amount of unknown columns.

I can use the AutoGenerateColumns feature to render all the returned columns
but I'm then having problems adding in 1 column at the right of the GridView
at runtime. This is because AutoGenerated columns aren't added to the
GridView's columns collection so any column created programmatically is
inserted at the start (first column in GridView).

If I disable AutoGenerateColumns, I can declaretively create the first 4
columns as I know what they are but there can be anywhere between 1-18
additional columns after this, with unknown column names (it's a crosstab
SP). With this method, I can't think of a way to find out how many "extra"
columns there are and programmatically create them.

Any advise/inspiration appreciated on how to approach this using either;

AutoGeneratedColumns and inserting a column at the end of the GridView
programmatically,
or,
Not using AtuoGeneratedColumns, declaretively creating the first 4 columns
and then programmatically creating the x amount of columns.

Thanks in advance.
Nov 19 '05 #1
3 2392
TJS
typically, I autogenerate the columns, then programmatically add additional
ones from there.


Nov 19 '05 #2
Yeah, but autogenerated columns aren't added to the GridView's columns
collection so any columns programmatically added to the gridview are added at
the beginning of the GridView.

Unless you can tell me how to set it up so that columns are added AFTER the
bound columns?

"TJS" wrote:
typically, I autogenerate the columns, then programmatically add additional
ones from there.


Nov 19 '05 #3
TJS
try something like this

'************************************************* ******
Sub Page_Init(sender As Object, e As EventArgs)
'
' dynamically add column to the datagrid
' This must be done in the Page_Init function
'
'************************************************* ******
Dim hc1 as new HyperLinkColumn
hc1.DataNavigateUrlField="reportsID"
hc1.DataNavigateUrlFormatString= "Report.aspx?rpt={0}"
hc1.Text="View"
PatientReportGrid.Columns.Add (hc1)

End Sub


"Mark Parter" <Ma********@discussions.microsoft.com> wrote in message
news:52**********************************@microsof t.com...
Yeah, but autogenerated columns aren't added to the GridView's columns
collection so any columns programmatically added to the gridview are added
at
the beginning of the GridView.

Unless you can tell me how to set it up so that columns are added AFTER
the
bound columns?

"TJS" wrote:
typically, I autogenerate the columns, then programmatically add
additional
ones from there.


Nov 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by GCeaser | last post: by
reply views Thread by jeffmagill | last post: by
3 posts views Thread by Richard Carpenter | last post: by
2 posts views Thread by Greg | last post: by
3 posts views Thread by Nathan Sokalski | last post: by
reply views Thread by leo001 | last post: by

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.