Problem solve Get help with specific problems with your technologies, process and projects.

Hiding columns with database ID data

I have developed a few database applications using VB6, VB.Net and VB.Net for PPC. I use ListViews to view data because I can hide columns and get data such as unique record Id from the hidden column. I am looking at developing a Web interface to the data using ASP.Net and want similar functionality. I have to access the data through an ODBC driver and need to display the data in a similar way to the VB.Net app, ie - hiding columns containing Database ID data. I have played with DataGrids but can't find a way to hide a column. Also, the Paging function doesn't seem to work. Is this possible with ASP.NET and should I be using another control? I look forward to your reply.
It's absolutely possible with the DataGrid. The trick is to disable the AutoGenerateColumns property of the control. Next, you can use the datagrid columns editor to add the columns you want to display. In order to keep the hidden ID around without the need to re-query the database, you should also use a custom templated column where you put the ID in a control with a hidden style (i.e. set its Class property, and create a CSS style with "display:none").

Afterwards, you can locate the ID for a row by using the FindControl( id ) method.

Finally, paging is *not* automatic. You must handle the PageIndexChanged event fired by the datagrid, where you basically set the new index, and rebind the data:
private void grdApproved_PageIndexChanged(object source,
    DataGridPageChangedEventArgs e)
  // Set the new index
  grdApproved.CurrentPageIndex = e.NewPageIndex;

  // Re-fill the dataset
  // Re-bind

Dig Deeper on ASP.NET and Ajax development

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.