Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Populate DropDownList w/ GridView Header Text

Status
Not open for further replies.

ccshadow

Programmer
Jan 29, 2004
33
US
I have a GridView bound with an SQLDataSource. Search functionality for the
GridView needs to be added through the use of a DropDownList containing all
of the visible fields from the GridView, in addition to a textbox for search
text. I want to avoid hard coding the values in the DropDownList. How can I
retrieve these values programmatically either from the SQLDataSource or the
GridView itself?

Thanks in advance.
 
Code:
        Dim gvc As System.Web.UI.WebControls.BoundField

        For Each gvc In GridView1.Columns
            If gvc.Visible = True Then
                DropDownList1.Items.Add(gvc.ToString)
            End If
        Next

Jim
 
Well this is the closest it's come to working! One problem though. It throws an error if I leave my template or command fields in the gridview. Works get if I delete those. ??
 
Ok try this:
[code}
Dim gvc As DataControlField

For Each gvc In GridView1.Columns
If gvc.Visible = True And gvc.GetType.ToString <> "System.Web.UI.WebControls.CommandField" Then
DropDownList1.Items.Add(gvc.ToString)
End If
Next
[/code]
 
Yes! I played around with the GetType, but just couldn't get it to cooperate. Thanks so much!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top