469,283 Members | 2,297 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,283 developers. It's quick & easy.

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 2347
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
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.