Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Get Gridview header row

Posted on 2007-07-28
12
Medium Priority
?
2,883 Views
Last Modified: 2008-01-09
I tried to use this to scan the header rows of a gridview after it's been databound
but the Me.GridviewHeaderRow has the first row of data in it.    How might I get at that header data?

            'Dim wrkCell As Integer = -1
            'Dim wrkH As GridViewRow = Me.GridView1.HeaderRow
            'For n As Integer = 0 To wrkH.Cells.Count - 1
            '      If wrkH.Cells(n).Text = "ID" Then
            '            wrkCell = n
            '            Exit For
            '      End If
            'Next

            'If wrkCell = -1 Then
            '      Return -1
            'End If
0
Comment
Question by:codequest
  • 7
  • 3
  • 2
12 Comments
 
LVL 96

Assisted Solution

by:Bob Learned
Bob Learned earned 600 total points
ID: 19586647
Are you talking about getting information from the column, like HeaderText?

Bob
0
 
LVL 2

Author Comment

by:codequest
ID: 19586664
Yes.  I want to search for the header column number (= cell number) for the column with the header text i'm search for.  That's so that if I add or delete columns to the gridview, a function that uses the post bound Gridview row contents can find the appropriate cell within the row by looking at the header text...I don't want to change a hardwired cell number that give the position of that cell.
0
 
LVL 96

Assisted Solution

by:Bob Learned
Bob Learned earned 600 total points
ID: 19586692
Are the columns all BoundFields, or is there a mix of BoundField and TemplateField?

Bob
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 2

Author Comment

by:codequest
ID: 19590000
They're all bound fields.
0
 
LVL 2

Author Comment

by:codequest
ID: 19590006
Doh!  Except that there are button fields.  I've spent the day sliding the cell number up and down as I modify the Gridview columns...seems like there should be a way to access the Gridview Header row that has the ColumnID's in it
0
 
LVL 96

Assisted Solution

by:Bob Learned
Bob Learned earned 600 total points
ID: 19591224
Untested:

For Each field As BoundField In Me.GridView1.Columns
Next field

Bob
0
 
LVL 8

Accepted Solution

by:
rodmjay earned 1400 total points
ID: 19593689
dim list as new list(of gridviewrow)
for each row as gridviewrow in gv.rows
if row.rowtype = gridviewrowtype.header then
list.add(row)
end if
next
0
 
LVL 2

Author Comment

by:codequest
ID: 19595614
Thanks for input.  This is the accepted syntax, but it never finds the row type = header

Dim wrkAL As New ArrayList
For Each row As GridViewRow In Me.GridView1.Rows
If row.RowType = DataControlRowType.Header Then
wrkAL.add(row)
End If
Next
Dim wrkRow As GridViewRow = wrkAL(0)

0
 
LVL 8

Expert Comment

by:rodmjay
ID: 19595922
yeah, i guess you are right, i was trying to remember it without vs in front of me, did it work for you?
0
 
LVL 2

Author Comment

by:codequest
ID: 19602640
No, it doesn't find the header row.   Part of the reason I expected to find the header row is that I use a routine like this in Javascript, where the GV table is just one table, including the header, so you just get row 0.  

In vb on the server, though (admittedly a completely different environment), GV.Rows seems to only include the data rows.  There's got to be a variable for GV header, however, the original code (at start of question) doesn't find it.  GV.HeaderRow seems to have the first row of data, not the column headers.
0
 
LVL 2

Author Comment

by:codequest
ID: 19603249
Here's a workaround

Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound

Select Case e.Row.RowType
Case DataControlRowType.Header
For n As Integer = 0 To e.Row.Cells.Count - 1
If e.Row.Cells(n).Text = "ID" Then
Session("GV1_IDColumn") = n
End If
Next
End Select
End Sub

Then pickup the session variable in the above routine.   Unless I'm modifying the GV row structure outside of VB (which I -think- I would notice doing :-) then this should work.
 
0
 
LVL 2

Author Comment

by:codequest
ID: 19629480
Wouldna dunnit as fast without the prompting, thus the points and score.  Thanks!
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…
Suggested Courses

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question