473,327 Members | 2,025 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

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 1397
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: David Whitney | last post by:
All: I have a control that renders a table. As the table is rendered, each row in the table is constructed by creating a run-time (dynamic) object that is derived from an HtmlTableRow. The row...
2
by: Daniel Walzenbach | last post by:
Hi, I created an ASP.NET Datagrid where a single row can be selected by clicking anywhere on the row (according to...
7
by: needin4mation | last post by:
Please Consider this code snippet: private void dgdHistory_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item ||...
3
by: Richard | last post by:
I'm trying to change a value of a cell based on another before the grid is displayed. I'm using the ItemDataBound event like this for a simple test: Select Case e.Item.ItemType Case...
10
by: JohnR | last post by:
I have a datatable as the datasource to a datagrid. The datagrid has a datagridtablestyle defined. I use the datagridtablestyle to change the order of the columns (so they can be different than...
3
by: Jeff | last post by:
Help.. I have been using: string sId = ((System.Web.UI.WebControls.TextBox)e.Item.Cells.Controls).Text; To get the value of a cell in my datagrid. When I set the cell to read only, I get...
1
by: mkrei | last post by:
I have datagrid that I format at runtime with tablestyles and adding columns. I have a DataGridBoolColumn that I have subclassed, but can't get the right result. I want to disable a cell based on...
2
by: Iain | last post by:
Hi All Using Delphi 2006 developer - C# Project I have the following 2 event handlers for the datagrid - see botton of page Both events will fire off correctly but i have a problem collecting...
0
by: =?Utf-8?B?U2Vhblc=?= | last post by:
It appears that in the .NET Framework 2.0, if you create a datagrid, set AllowPaging="true", and set AutoGenerateColumns="true" the behaviour of the paging cell is incorrect, the ColumnSpan...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.