GridView help required

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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.
 
typically, I autogenerate the columns, then programmatically add additional
ones from there.
 
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?
 
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
 
Back
Top