By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,621 Members | 1,206 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,621 IT Pros & Developers. It's quick & easy.

Dynamic DataGrid

P: n/a
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("ConnectionStrin g")
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").ColumnNameTh en
objbc.Visible = False
End If
If objbc.DataField = MyDataSet.Tables(0).Column("PkgQuantity").ColumnNa meThen
objbc.Visible = False
End If
If objbc.DataField = MyDataSet.Tables(0).Columns("PrintName").ColumnNam e Then
objbc.Visible = False
End If

dgItemDetail.DataSource = MyDataSet.Tables(0)
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!
Joe Goeke
Aug 18 '05 #1
Share this Question
Share on Google+
1 Reply

P: n/a
CanoeGuy wrote:
I have been trying for the last two weeks to display a dynamic

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.
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
Aug 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.