Ask the Expert

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
  adApproved.Fill(dsApproved);
  // Re-bind
  grdApproved.DataBind();
}

This was first published in June 2004

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to: