Thursday, March 29, 2012
set cell color while rendered in a datagrid
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?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" <Ofer@.discussions.microsoft.com> wrote in message
news:574957A7-2D07-44A7-95BD-69B36E77C458@.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?
>
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" <Ofer@.discussions.microsoft.com> wrote in message
> news:574957A7-2D07-44A7-95BD-69B36E77C458@.microsoft.com...
>
>
You can use
If e.Item.ItemType = ListItemType.Item OrElse
e.Item.ItemType = ListItemType.AlternatingItem Then
' Your code here
End If
HTH
Elton Wang
elton_wang@.hotmail.com
>--Original Message--
>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:
>
datagrid, and from there
OnItemDataBound="MyGrid_OnItemDataBound" ....
DataGridItemEventArgs e)
set the colors
message
69B36E77C458@.microsoft.com...
>'></ItemStyle>
an event of
>.
>
set cell color while rendered in a datagrid
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?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" <Ofer@.discussions.microsoft.com> wrote in message
news:574957A7-2D07-44A7-95BD-69B36E77C458@.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?
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" <Ofer@.discussions.microsoft.com> wrote in message
> news:574957A7-2D07-44A7-95BD-69B36E77C458@.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?
>
You can use
If e.Item.ItemType = ListItemType.Item OrElse
e.Item.ItemType = ListItemType.AlternatingItem Then
' Your code here
End If
HTH
Elton Wang
elton_wang@.hotmail.com
>--Original Message--
>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" <Ofer@.discussions.microsoft.com> wrote in
message
>> news:574957A7-2D07-44A7-95BD-
69B36E77C458@.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?
>>>>
>>
>>
>.
Set Column Headertext
I have a Datagrid with a templatecolumn, where I add at design time. I also checked the "create columns automatically"
I would like to change the headertext of columns created automatically, but i don't know in which event I can do that
Can you help me
P.S. I tryied to set the headertext in the "PreRender" event of the DataGrid, but in this point the grid has still only the templatecolumn, and the others columns aren't created yet
Thank you
Alessandro RossHi, Alessandro Rossi,
If you extend the DataGrid class (inherit from it) the best place is the
OnDataBinding protected method. You should first call base.OnDataBinding(e);
of course.
If you are simply using the DataGrid class - set the headertexts after you
call DataBind() because the columns are in fact created with this call.
Hope this helps
Martin
"Alessandro Rossi" <alessandro.rossi@.areait.net> wrote in message
news:528CD483-7F36-4D2A-8760-24CD36F0BE8A@.microsoft.com...
> Hi,
> I have a Datagrid with a templatecolumn, where I add at design time. I
also checked the "create columns automatically".
> I would like to change the headertext of columns created automatically,
but i don't know in which event I can do that.
> Can you help me?
> P.S. I tryied to set the headertext in the "PreRender" event of the
DataGrid, but in this point the grid has still only the templatecolumn, and
the others columns aren't created yet.
> Thank you.
> Alessandro Rossi
Thursday, March 22, 2012
Set headertext in datagrid programatically
The dataadapter,dataset and databind() code runs in a button eventhandler
The headertext is currently determined by the column names of my SQL select
statement there.
How can I change the headertext programatically in the codebehind? ... I do
n't want to change the preexisting code if at all possible.in your itemdatabound event handler, you can test for the headeritem and
then use the text property attached to the cell object to change the text
e.item.cells[4].text = "vapor"
Regards,
Alvin Bruney
[ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
Got tidbits? Get it here... http://tinyurl.com/27cok
"mg" <mg@.theworld.com> wrote in message
news:88A2B342-0B07-4CD5-80AC-8C989FE5C2EA@.microsoft.com...
>I create a datagrid using the Web Forms Toolbox
> The dataadapter,dataset and databind() code runs in a button eventhandler
> The headertext is currently determined by the column names of my SQL
> select statement there.
> How can I change the headertext programatically in the codebehind? ... I
> don't want to change the preexisting code if at all possible.
Set headertext in datagrid programatically
The dataadapter,dataset and databind() code runs in a button eventhandler
The headertext is currently determined by the column names of my SQL select statement there
How can I change the headertext programatically in the codebehind? ... I don't want to change the preexisting code if at all possible.in your itemdatabound event handler, you can test for the headeritem and
then use the text property attached to the cell object to change the text
e.item.cells[4].text = "vapor"
--
Regards,
Alvin Bruney
[ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
Got tidbits? Get it here... http://tinyurl.com/27cok
"mg" <mg@.theworld.com> wrote in message
news:88A2B342-0B07-4CD5-80AC-8C989FE5C2EA@.microsoft.com...
>I create a datagrid using the Web Forms Toolbox
> The dataadapter,dataset and databind() code runs in a button eventhandler
> The headertext is currently determined by the column names of my SQL
> select statement there.
> How can I change the headertext programatically in the codebehind? ... I
> don't want to change the preexisting code if at all possible.