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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Making DG Column Visible = False 1

Status
Not open for further replies.

jfrost10

Programmer
Jun 3, 2001
2,004
CA
Hey guys,

I'm working on the search functionality of our member portal. The result datagrid's columns dynamically change depending on what entity the user is searching on. The problem I'm having is that the first column after the button column needs to be invisible because it holds the record's ID. I tried this:

dgResults.DataSource = objSU.GetSearchResults(strSQL)
dgResults.DataBind()
dgResults.Columns(1).Visible = False

But that didn't work, and trying this:

dgResults.DataSource = objSU.GetSearchResults(strSQL)
dgResults.Columns(1).Visible = False
dgResults.DataBind()

produced an error.

So then I thought: I'll just add a column through code, but the DataGridColumn object doesn't seem to have a DataField property.

Any thoughts on how I could get this working?

Thanks,

D
 
Hey Jack check out this thread. The guy there seems to have gotten the column hidden but was having problems with it.

thread855-378526 That'l do donkey, that'l do
[bravo] Mark
If you are unsure of forum etiquette check here faq796-2540
 
Thanks Mark.

His problem is a bit different though:
he mentions that both columns are bound columns, whereas mine aren't; they all get created dynamically.

D
 
So when you say that they get created dynamically, do you mean that you specifically create each column at run-time, or do you let your datagrid create its own columns based on the sql statement you pass there?
penny1.gif
penny1.gif
 
I'm letting my datagrid create its own columns based on dataset returned from my sql statement.

but what I'd LIKE to do is create the columns at run time (which would give me total control over how the data is shown).

btw, thanks again for that tip on disabling the back button a few posts ago. Just got around to implementing it, and it works like a charm.

D
 
Your welcome on that tip. I love the simplicity of it.

Anyway, as for your question, I'm afraid you're going to have to create your own columns, because when you let the datagrid create its own, you give up the control to hide/show them (among other things).

Should be pretty simple... just loop through the columns of your datasource, setting the properties on each datagrid column as you go, and then .dataBind()

Should be a bit tedious, but easy, nonetheless.
penny1.gif
penny1.gif
 
see thats what I thought, but its borderline frustrating more than anything else:

For some reason I can't find where the DataField property of a datagrid column is. Its not at the first level, as i would have thought it was, and there's nothing really obvious in the next level that would point to where it is either. So I can add columns in the code, I just can't tell it what fields i want bound to which columns.

D
 
Ah, BoundColumn, not just a column...never even crossed my mind.

Thanks Paul, you the man.

D
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top