ItemDataBound event

X

Xu ChunMing

Hi All,
I see the following on MSDN:

The DataGrid control supports several events. One of them, the ItemCreated
event, gives you a way to customize the item-creation process. The
ItemDataBound event also gives you the ability to customize the DataGrid
items, but after the data is available for inspection. For example, if you
were using the DataGrid control to display a to-do list, you could display
overdue items in red text, completed items in black text, and other tasks in
green text.

I nearly want to do the same thing,
but in the event ,I can't access the value I wanted with the commented
line, but this statemetn works well on the Item Updat event.

public void MyDataGrid_DataBound(Object sender, DataGridItemEventArgs e)
{
//string s1
=((System.Web.UI.WebControls.TextBox)e.Item.Cells[7].FindControl("edit_Sate"
)).Text;
if(s1=="UT")
e.Item.BackColor =Color.Green ;
}

I wonder how to access the one of the cell's bounded value of the just added
row.

Thanks!
 
A

Arvind P Rangan

Hi ChunMing,
Have you tried doing this in DAtaGrid_ItemCreate
under this
try in
if e.Item.ItemType = ListItemType.AlternatingItem Or e.Item.ItemType =
ListItemType.Item
=((System.Web.UI.WebControls.TextBox)e.Item.Cells[7].FindControl("edit_Sate"
)).Text;
if(s1=="UT")
e.Item.BackColor =Color.Green ;
your code to change the color.


this option is for listing only not in edit mode.

Check it out.
Same syntax under this option.
 
V

Volkan Karaboða

checkout the message which subject's is "changing row color depending on a
cell value"
at this group sended 20/02/2004

I think it helps you...
 

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

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top