Webform Datagrid question - Altering text in a cell

  • Thread starter Thread starter Sam Evans
  • Start date Start date
S

Sam Evans

All:

I've looked all over (and probably not in the right places) to try and
find some example code, or documentation on how I can modify the text in
a cell of a datagrid.

I've found information saying it's best to override the paint method,
and other information saying it's best to use the prerender event.

Can anyone point me in the right direction? Thanks and sorry for the
dumb question, I'm trying to learn C# coming from a Perl background. :)

-Sam
 
Hi,

there is no paint event in webforms, you can either use prerender event or
calling a method at bind time, below is an example of the latter :

<asp:templatecolumn ItemStyle-VerticalAlign="Top" ItemStyle-Width="110"
ItemStyle-HorizontalAlign="left" >
<itemtemplate>
<span ><%# GetFirstDocumentOfRecord( Container.DataItem) %></span>
</itemtemplate>
</asp:templatecolumn>

GetFirstDocumentOfRecord is a protected method declared in the code behind.


cheers,
 
Thanks for the reply.

I am not sure how I would create the GetFirstDocumentOfRecord though.
Am I going through the DataGrid items list to get it?
 
Nevermind, I figured out a different way to do it..

Using the ItemDataBound event in the datagrid I was able to modify the
e.Item[0].Cells.Text

Thanks, though!
 
Hi,

It's a method declared in the code behind like this:

protected string GetFirstDocumentOfRecord ( object o )
{
//do whatever
return "the text you want";
}

The good thing about this is that it's mucho more clear the process and you
can modify it easily

cheers,
 
Back
Top