mdunlap99
asked on
Find gridview column datafield in code.
I am currently building a filtering mechanism for a gridview. I am binding the gridview to an SQLDataSource. My user will select a column name from a dropdown list (populated at page load from gridview.columns(i).Header Text values) and enter a search value in a textbox. What I want to do at this point is to determine programmatically what data field is associated with the select column HeaderText value. What I need to locate is the DataField value associated with the column. Can you help?
Thanks!
Thanks!
ASKER
I am not looking for the data, just the data field name so that I can construnct a select statement. For instance, the gridview column header text is 'Product Name'. The field name in the SQL database if 'prod_name'. If the user selects 'Product Name' from the dropdown list, I need to change the SQL "select to 'select * where prod_name like ...".
Ok I understand.
That depends on your column, but if you are using BoundFields you should be able to use something like this.
Gridview.columns(i).DataFi eld
My hunch though is you're going to tell me this doesn't work, since it seems so obvious :-)
That depends on your column, but if you are using BoundFields you should be able to use something like this.
Gridview.columns(i).DataFi
My hunch though is you're going to tell me this doesn't work, since it seems so obvious :-)
ASKER
Your hunch is right on. DataField does not seem to be a property of the Columns(i) item. Seems there are only headerstyle, Itemstyle, etc. properties there. Thus the 250 points, eh!!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Bingo! That did the trick. Thanks for the help!!
Glad you got it to work. Did you accidently click the wrong link to accept my comment? I see this notice (which as soon as I post here will go away)
--
Author Comment
Is this what you were looking for?
Yes No
mdunlap99:
Bingo! That did the trick. Thanks for the help!!
Notice: The Asker has requested that this comment be accepted as the solution and the points broken down as follows, with any remaining points refunded to the Asker's account:
250 points to 21876103 by raterus
If you object to this action, you have until 7/3/2008 to post a comment describing your objection. This will generate a request in Community Support for Moderator review. If no Expert objects, this question will be closed as described above.
--
Author Comment
Is this what you were looking for?
Yes No
mdunlap99:
Bingo! That did the trick. Thanks for the help!!
Notice: The Asker has requested that this comment be accepted as the solution and the points broken down as follows, with any remaining points refunded to the Asker's account:
250 points to 21876103 by raterus
If you object to this action, you have until 7/3/2008 to post a comment describing your objection. This will generate a request in Community Support for Moderator review. If no Expert objects, this question will be closed as described above.
ASKER
raterus,
I screwed the point submit. I am a new member and don't know why this happened. I will get it fixed, though.
I screwed the point submit. I am a new member and don't know why this happened. I will get it fixed, though.
ASKER
Do you know how I can get this error undone and get the points credited to you?
ASKER
I see an autorequest in my list to accept and award point. I hope this clears it up.
ASKER
OK, we're flush,eh!
gridview.rows(#).Cells(i)