Function for GridView

S

sck10

Hello, I am using the following GridView control. What I would like to do
is for each row, test to see if the DataField="Product" value = "Total". If
so, make the text for each bound field bold. Looking through the
documentation, I am assuming that I would use the event (RowCreated). My
question is, how would I reference the datafield in a function?

Thanks, in advance, sck10


<asp:GridView ID="gvWebDocList" Runat="server" DataSourceID="dsWebDocList"
AutoGenerateColumns="False" AllowPaging="True" PageSize="40">

<Columns>
<asp:BoundField DataField="Product" HeaderText="Product" />
<asp:BoundField DataField="ProductCount" HeaderText="Total" />
</Columns>
</asp:GridView>
 
J

Jeffrey Palermo [MCP]

Sck10,
You will have to muck with the GridView's Controls collection to get a
reference to the textboxes rendered in each column. In the RowCreated or
RowDataBound event, you can use e.Row.Controls to go through the fields.
Turn Trace on to visually see the page control hierarchy. This will help
you locate the controls you need. If you have to do some special things
with the rows, using a TemplateColumn would make it easier. That way you
would get to name the controls so you can find them better.

Best regards,
Jeffrey Palermo
 
S

Steven Cheng[MSFT]

Thanks for Jeffery's suggestions.

Hi Sck10,

From your description, I'm wondering whether you're wanting to set the bold
font for all the column headers in the GridView? If so , you can consider
using the HeaderStyle or any other style setting for the grid rather than
manually retriving the text and set bold on them. How do you think ?
If there're any thing I'm misunderstanding, please feel free to let me
know. Thanks.

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
S

sck10

Hi Steve,

What I am trying to do is determine if the text for the DataField that is
retrieving the "Product" data is equal to "Total". If so, then make all the
data fields for that particular row bold. My last row of the data being
pulled from SQL Server is a totals row.
 
S

Steven Cheng[MSFT]

Thanks for your followup Sck10,

Then, I think you can consider Jeffrey 's suggestion on making use of the
ItemBound or ItemCreated event and retrive the binded data and compare
their values.
Thanks.

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 

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

Top