Problem:
Do you have database column names that look like this?
As we all know, database column names are rarely created with the end-user in mind.
Cause:
As you probably know, the developer or dba generally base the name on the column definition. Therefore, the first name will probably called FirstName, last name = LastName, and so forth.
But would you really want to display these unformatted column names to your end-users?
Possible Solutions:
In most cases you'll want to correct the column names before the end-user ever sees them. You can solve this problem in a couple ways. However, they are not the most elegant solutions:
1) You can change your query to display the correct name. This requires you do extra work of rewriting each column name correctly, i.e.:
SELECT FirstName AS "First Name", LastName AS "Last Name" ...
2) Or you can change it in the grid. This too requires you to do extra work.
A Better Option:
Ideally, you want your grid to be smart enough to figure out that if the column is labeled, CustomerID, then "Customer ID" should be displayed.
ASPxGridView does this by default. See for yourself.
That Invoices query from above is now displayed correctly within the ASPxGridView:
Did you notice how the column names are already formatted for you?
You can save time by not having to re-code every column name.
Under Your Control:
You may not always want the smart parsing, so with the ASPxGridView you have the power to choose.
You can set the Caption property of the column within the columns collection of the ASPxGridView. Let's take a closer look:
Simply set AutoGenerateColumns to False and Refresh the Schema:
The Columns collection is now rebuilt using the column names that were specified in the query. You can still set the Caption property of any of the columns to your liking:
What if you wanted to use the smart parsing but still have custom names on some columns? No problem.
You can also use the Caption property together with the smart name parsing.
With AutoGenerateColumns set to True, simply assign the column name during runtime:
protected void ASPxGridView1_DataBound(object sender, EventArgs e)
{
ASPxGridView1.Columns[0].Caption = "Vessel Name";
}
Best of both worlds:
Pretty cool, huh?
Free DevExpress Products – Get Your Copy Today
The following free DevExpress product offers remain available. Should you have any questions about the free offers below, please submit a ticket via the
DevExpress Support Center at your convenience. We’ll be happy to follow-up.