Dynamic DataGrid

C

CanoeGuy

I have been trying for the last two weeks to display a dynamic DataGrid. The
data that I'm pulling from a SQL Server DB will have whole columns that will
be either NULL or 0. I want to display only the fields that have actual data
in them and either not display or hide the columns that have NULL or 0
values. As an example, one page may need to display a total of 5 columns and
another page may need to display three columns based on the product category
the user chooses. I have done this in classic ASP, but I can't figure out
how to do it with the DataGrid and ASP.NET.

The code I have so far looks like this.

Dim strFamily as String
strFamily = Request.QueryString("fam")
Dim strConnection as String, sqlConn as SQLConnection
strFamily = Request.QueryString("fam")
strConnection = ConfigurationSettings.AppSettings("ConnectionString")
sqlConn = New SqlConnection(strConnection)

Dim MyDataAdapter as SQLDataAdapter, MyDataSet as New DataSet
MyDataAdapter = New SQLDataAdapter("SELECT * FROM Items WHERE Part = '" &
Request.QueryString("part") & "'", strConnection)

MyDataAdapter.Fill(MyDataSet, "Items")

Dim i as Integer

'To navigate through the records.
For i = 0 To MyDataSet.Tables(0).Columns.Count - 1
Dim objbc As New BoundColumn()
objbc.DataField = MyDataSet.Tables(0).Columns(i).ColumnName
objbc.HeaderText = MyDataSet.Tables(0).Columns(i).ColumnName

If objbc.DataField = MyDataSet.Tables(0).Columns("Part").ColumnName Then
objbc.Visible = False
End If
If objbc.DataField = MyDataSet.Tables(0).Columns("Footnote").ColumnName Then
objbc.Visible = False
End If
If objbc.DataField = MyDataSet.Tables(0).Colum("Packaged").ColumnNameThen
objbc.Visible = False
End If
If objbc.DataField = MyDataSet.Tables(0).Column("PkgQuantity").ColumnNameThen
objbc.Visible = False
End If
If objbc.DataField = MyDataSet.Tables(0).Columns("PrintName").ColumnName Then
objbc.Visible = False
End If

dgItemDetail.Columns.Add(objbc)
dgItemDetail.DataSource = MyDataSet.Tables(0)
dgItemDetail.DataBind()
Next 'i

Any help is greatly appreciated. I'm already losing my hair and the last
few days it hasn't been getting any better!
 
B

Bob Barrows [MVP]

CanoeGuy said:
I have been trying for the last two weeks to display a dynamic
DataGrid.

There was no way for you to know it, but this is a classic asp newsgroup.
While you may be lucky enough to find a dotnet-knowledgeable person here who
can answer your question, you can eliminate the luck factor by posting your
question to a group where those dotnet-knowledgeable people hang out. I
suggest microsoft.public.dotnet.framework.aspnet.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,200
Latest member
LaraHunley

Latest Threads

Top