Data Binding - ASP 2.0

  • Thread starter Thread starter dm1608
  • Start date Start date
D

dm1608

I'm binding a column to a datagrid and would like to convert the column to
uppercase.

I notice that if I edit the GridView column, I can add formatting such as
{0:d} and {0:c} to the data item.

How can I convert this item to Uppercase?

I suppose I could do it via SQL, but I want to know how to do it using code.

Thanks
 
If you want formatting that isn't covered by the format strings, your
best bet is to handle the databinding events of your GridView.

<code>

protected void MyGridView_RowDataBound(object sender,
GridViewRowEventArgs e)
{
const myUppercaseColumnIndex = 1;
// don't handle headers or footers
if(e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[myUppercaseColumnIndex].Text =
e.Row.Cells[myUp..].ToUpper();
}
}

</code>
 
Thanks for the response.

I have a couple issues though --

1) It didn't like the const line. Something about the = sign and receiving
an "no identifier" message. I simply hardcoded the column for now.

2) Apparently the ToUpper() function is not part of the Cell class or
whatever. No worky??


Also, where did you obtain the Grid events info, etc? Are there any books
that reference how to do all these things.

This is really cool stuff.


Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top