troubleshooting Question

Searching a GridView?

Avatar of directxBOB
directxBOBFlag for Ireland asked on
Visual Basic.NET
5 Comments2 Solutions271 ViewsLast Modified:
I have a Gridview which is bound to a datasource.

I want to check that certain columns within that Gridview are empty. I don't want to have to rely on indexes to find the right column as the DBA has a habit of changing certain tables so I would prefer to have something that would work irrespective of what he does in the background.

If it were a DatabTable I could do :

        For Each row As DataRow In priceBandTable.Rows
            If row.Item("ProductId") = cbProduct.SelectedValue Then
                If (row.Item(ComboBox1.Text) = ComboBox1.Text Then
                    lblmessage.Text = "Error : This Price Band is already set."
                    Exit Sub
                End If
            End If

As with a DataTable I can pull out the exact columns based on names (Column Names will not change, just more will be added, and they may be reordered)

So I've been trying to get something like:

        For Each row As GridViewRow In Me.GridView2.Rows
            If row.Cells(0).Text = cbProduct.SelectedValue Then
                'search the columns.
                For c As Integer = 0 To row.Cells.Count
                    If  row.Cells(c)????? = ComboBox1.Text Then
                        lblmessage.Text = "Error : This Price Band is already set."
                        Exit Sub
                    End If
                Next c
            End If

But as you can see I'm stuck with this line, as I have no idea howto get a particular cells Name.

row.Cells(c)????? = ComboBox1.Text

Any ideas?

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 2 Answers and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros