470,614 Members | 1,556 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,614 developers. It's quick & easy.

set cell color while rendered in a datagrid

I use the code: <asp:BoundColumn DataField="EFF_END_DT"
SortExpression="EFF_END_DT" HeaderText="Effective End"
DataFormatString="{0:d}">
<ItemStyle ForeColor= '<% # MyColor(
DataBinder.Eval(Container.DataItem, "EFF_END_DT"))%>'></ItemStyle>
</asp:BoundColumn>
to have red date is it is over and blue if not!
But I get an error:
Compiler Error Message: BC30676: 'DataBinding' is not an event of
'System.Web.UI.WebControls.TableItemStyle'.

how can I resolve this?
Nov 19 '05 #1
3 1342
i think your trying to user the OnItemDataBound method

In this method you can access each row of your datagrid, and from there
determine if the date should be read or not.

in the .aspx page
<asp:DataGrid id="MyGrid" OnItemDataBound="MyGrid_OnItemDataBound" .....

then in the .cs page

public void MyGrid_OnItemDataBound(object Sender, DataGridItemEventArgs e)
{
//From here you can access your bound column and set the colors
}
"Ofer" <Of**@discussions.microsoft.com> wrote in message
news:57**********************************@microsof t.com...
I use the code: <asp:BoundColumn DataField="EFF_END_DT"
SortExpression="EFF_END_DT" HeaderText="Effective End"
DataFormatString="{0:d}">
<ItemStyle ForeColor= '<% # MyColor(
DataBinder.Eval(Container.DataItem, "EFF_END_DT"))%>'></ItemStyle>
</asp:BoundColumn>
to have red date is it is over and blue if not!
But I get an error:
Compiler Error Message: BC30676: 'DataBinding' is not an event of
'System.Web.UI.WebControls.TableItemStyle'.

how can I resolve this?

Nov 19 '05 #2
Thanks! that was helpful.
Would you know why if the results is 2 rows the event fires 4 times
2 times with the value I axpect an 2 with " "

my vb is:
Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles
DataGrid1.ItemDataBound
Debug.WriteLine(e.Item.Cells(6).GetType.ToString) 'always
System.Web.UI.WebControls.TableCell
Debug.WriteLine(e.Item.Cells(6).Text)
End Sub
End Class

"Grant Merwitz" wrote:
i think your trying to user the OnItemDataBound method

In this method you can access each row of your datagrid, and from there
determine if the date should be read or not.

in the .aspx page
<asp:DataGrid id="MyGrid" OnItemDataBound="MyGrid_OnItemDataBound" .....

then in the .cs page

public void MyGrid_OnItemDataBound(object Sender, DataGridItemEventArgs e)
{
//From here you can access your bound column and set the colors
}
"Ofer" <Of**@discussions.microsoft.com> wrote in message
news:57**********************************@microsof t.com...
I use the code: <asp:BoundColumn DataField="EFF_END_DT"
SortExpression="EFF_END_DT" HeaderText="Effective End"
DataFormatString="{0:d}">
<ItemStyle ForeColor= '<% # MyColor(
DataBinder.Eval(Container.DataItem, "EFF_END_DT"))%>'></ItemStyle>
</asp:BoundColumn>
to have red date is it is over and blue if not!
But I get an error:
Compiler Error Message: BC30676: 'DataBinding' is not an event of
'System.Web.UI.WebControls.TableItemStyle'.

how can I resolve this?


Nov 19 '05 #3
You can use

If e.Item.ItemType = ListItemType.Item OrElse
e.Item.ItemType = ListItemType.AlternatingItem Then
' Your code here
End If
HTH

Elton Wang
el********@hotmail.com
-----Original Message-----
Thanks! that was helpful.
Would you know why if the results is 2 rows the event fires 4 times2 times with the value I axpect an 2 with " "

my vb is:
Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e AsSystem.Web.UI.WebControls.DataGridItemEventArgs ) Handles
DataGrid1.ItemDataBound
Debug.WriteLine(e.Item.Cells (6).GetType.ToString) 'alwaysSystem.Web.UI.WebControls.TableCell
Debug.WriteLine(e.Item.Cells(6).Text)
End Sub
End Class

"Grant Merwitz" wrote:
i think your trying to user the OnItemDataBound method

In this method you can access each row of your datagrid, and from there
determine if the date should be read or not.

in the .aspx page
<asp:DataGrid id="MyGrid" OnItemDataBound="MyGrid_OnItemDataBound" .....
then in the .cs page

public void MyGrid_OnItemDataBound(object Sender, DataGridItemEventArgs e) {
//From here you can access your bound column and set the colors }
"Ofer" <Of**@discussions.microsoft.com> wrote in message news:574957A7-2D07-44A7-95BD-

69**********@microsoft.com...
>I use the code: <asp:BoundColumn DataField="EFF_END_DT"
> SortExpression="EFF_END_DT" HeaderText="Effective End"
> DataFormatString="{0:d}">
> <ItemStyle ForeColor= '<% # MyColor(
> DataBinder.Eval(Container.DataItem, "EFF_END_DT"))%'></ItemStyle> > </asp:BoundColumn>
> to have red date is it is over and blue if not!
> But I get an error:
> Compiler Error Message: BC30676: 'DataBinding' is not an event of > 'System.Web.UI.WebControls.TableItemStyle'.
>
> how can I resolve this?
>
>


.

Nov 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by David Whitney | last post: by
2 posts views Thread by Daniel Walzenbach | last post: by
7 posts views Thread by needin4mation | last post: by
3 posts views Thread by Richard | last post: by
reply views Thread by =?Utf-8?B?U2Vhblc=?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.