Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Manipulating a datagrid one item at a time?

Status
Not open for further replies.

Junior1544

Technical User
Apr 20, 2001
1,267
US
I have a page setup with a datagrid.

I would like to change the background color of a line if one of the items in the line fit's certain criteria...

I know the logic of what i need, I can't figure out how to make the
OnDataBound event work though... Any help would be great...

--James
junior1544@jmjpc.net
Life is change. To deny change is to deny life.
 
Well I've never used the OnDataBound event to do this. What I do is simply put the logic in the Item Template
For example, here is one which displays either of two images depending on the value of one of the data fields being bound

<ItemTemplate>
<asp:Image id=Image1 ImageUrl='<%#iif (databinder.eval(container, &quot;DataItem.Complete&quot;), &quot;images/tick.gif&quot;, &quot;images/cross.gif&quot;) %>' Runat=&quot;server&quot;>
</asp:Image>
</ItemTemplate>

Your criteria are more complicated than a simple Iif function can handle. Rather than making the code inside the <%# %> too complicated, what I would do is create a protected function in the code behind to take in the data and return the background color you want the row to be.

If this does not help you, post back and I'll do a better example.

Mark [openup]
 
jr: Scott Mitchell has an excellent 13 part series on the DataGrid, using examples of &quot;onItemDataBound&quot; events. There are also a handful of discussions that have occurred here at Tek-Tips re: this event. Here is a link to the 13 part series, you might find an example there:


You might do a search on Paul(link9) and Zarcom; each have submitted examples within the last 6 months on this topic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top