471,348 Members | 1,781 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

How to set first column's property of header row?

I use a datagrid included in a repeater.

as following: (.aspx)
<asp:repeater id="rp_perform" Runat="server">
<HeaderTemplate>
<table border="0" bgcolor="gray" cellspacing="0" cellpadding="0">
</HeaderTemplate>
<ItemTemplate>
<tr bgcolor="white">
<td width="100%">
<asp:datagrid id="dg_perform" Runat="server" DataSource='<%#
GetDataTable((int)DataBinder.Eval(Container.DataIt em, "Product_No")) %>'
AutoGenerateColumns="True" GridLines="Both" BorderColor="DimGray"
BorderWidth="2" CellPadding="3" CellSpacing="0">
<HeaderStyle BackColor="#99ccff" Font-Bold="True" />
<ItemStyle BackColor="#FFFFCC" />
</asp:datagrid>
</td>
</tr>
</ItemTemplate>
<SeparatorTemplate>
<tr>
<td height="25" bgcolor="white"></td>
</tr>
</SeparatorTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:repeater>

I want to change first column's backcolor of header row in each datagrid.
I catch every datagrid, it can set item's settings, but can't set first
column's settings of header row.

How to do it?
Thanks.

Nov 29 '05 #1
4 2345
Hi,

You could add an ItemDataBound event to the DataGrid. Then, in the event
handler, check when you get a header type of an item. Get the first
column, and change the color programatically.

-Lenard
Grace wrote:
I use a datagrid included in a repeater.

as following: (.aspx)
<asp:repeater id="rp_perform" Runat="server">
<HeaderTemplate>
<table border="0" bgcolor="gray" cellspacing="0" cellpadding="0">
</HeaderTemplate>
<ItemTemplate>
<tr bgcolor="white">
<td width="100%">
<asp:datagrid id="dg_perform" Runat="server" DataSource='<%#
GetDataTable((int)DataBinder.Eval(Container.DataIt em, "Product_No")) %>'
AutoGenerateColumns="True" GridLines="Both" BorderColor="DimGray"
BorderWidth="2" CellPadding="3" CellSpacing="0">
<HeaderStyle BackColor="#99ccff" Font-Bold="True" />
<ItemStyle BackColor="#FFFFCC" />
</asp:datagrid>
</td>
</tr>
</ItemTemplate>
<SeparatorTemplate>
<tr>
<td height="25" bgcolor="white"></td>
</tr>
</SeparatorTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:repeater>

I want to change first column's backcolor of header row in each datagrid.
I catch every datagrid, it can set item's settings, but can't set first
column's settings of header row.

How to do it?
Thanks.

Nov 29 '05 #2
I write as following:
DataGrid dg=(DataGrid)obj;
dg.Columns[0].HeaderStyle.BackColor=Color.Green;

but it shows error message.
I check dg.Columns.Count, it is always 0.

Could you write some codes to teach me how to solve it?
Thanks.

"Lenard Gunda" wrote:
Hi,

You could add an ItemDataBound event to the DataGrid. Then, in the event
handler, check when you get a header type of an item. Get the first
column, and change the color programatically.

-Lenard
Grace wrote:
I use a datagrid included in a repeater.

as following: (.aspx)
<asp:repeater id="rp_perform" Runat="server">
<HeaderTemplate>
<table border="0" bgcolor="gray" cellspacing="0" cellpadding="0">
</HeaderTemplate>
<ItemTemplate>
<tr bgcolor="white">
<td width="100%">
<asp:datagrid id="dg_perform" Runat="server" DataSource='<%#
GetDataTable((int)DataBinder.Eval(Container.DataIt em, "Product_No")) %>'
AutoGenerateColumns="True" GridLines="Both" BorderColor="DimGray"
BorderWidth="2" CellPadding="3" CellSpacing="0">
<HeaderStyle BackColor="#99ccff" Font-Bold="True" />
<ItemStyle BackColor="#FFFFCC" />
</asp:datagrid>
</td>
</tr>
</ItemTemplate>
<SeparatorTemplate>
<tr>
<td height="25" bgcolor="white"></td>
</tr>
</SeparatorTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:repeater>

I want to change first column's backcolor of header row in each datagrid.
I catch every datagrid, it can set item's settings, but can't set first
column's settings of header row.

How to do it?
Thanks.

Nov 29 '05 #3

Here is a code for an item data bound event handler, I think this should
work :)

private void DataGrid1_ItemDataBound(
object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
// check that item is header
if ( e.Item.ItemType == ListItemType.Header )
{
// check that we have cells
if ( e.Item.Cells.Count > 0 )
{
e.Item.Cells[0].BackColor = Color.Green;
}
}
}

This should run when data is bound to the grid. If checks if the item is
a header item, and if it is, checks if there are any cells. If then
changes the backcolor of that cell. You can also access almost anything
in the DataGrid in a similar way, after it has been built (data bound).

Columns count can be 0, if you use automatic column creation. In that
case, the columns are automatically created for you, but are never added
to the Columns collection itself.

-Lenard
Grace wrote:
I write as following:
DataGrid dg=(DataGrid)obj;
dg.Columns[0].HeaderStyle.BackColor=Color.Green;

but it shows error message.
I check dg.Columns.Count, it is always 0.

Could you write some codes to teach me how to solve it?
Thanks.

"Lenard Gunda" wrote:

Hi,

You could add an ItemDataBound event to the DataGrid. Then, in the event
handler, check when you get a header type of an item. Get the first
column, and change the color programatically.

-Lenard
Grace wrote:
I use a datagrid included in a repeater.

as following: (.aspx)
<asp:repeater id="rp_perform" Runat="server">
<HeaderTemplate>
<table border="0" bgcolor="gray" cellspacing="0" cellpadding="0">
</HeaderTemplate>
<ItemTemplate>
<tr bgcolor="white">
<td width="100%">
<asp:datagrid id="dg_perform" Runat="server" DataSource='<%#
GetDataTable((int)DataBinder.Eval(Container.Dat aItem, "Product_No")) %>'
AutoGenerateColumns="True" GridLines="Both" BorderColor="DimGray"
BorderWidth="2" CellPadding="3" CellSpacing="0">
<HeaderStyle BackColor="#99ccff" Font-Bold="True" />
<ItemStyle BackColor="#FFFFCC" />
</asp:datagrid>
</td>
</tr>
</ItemTemplate>
<SeparatorTemplate>
<tr>
<td height="25" bgcolor="white"></td>
</tr>
</SeparatorTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:repeater>

I want to change first column's backcolor of header row in each datagrid.
I catch every datagrid, it can set item's settings, but can't set first
column's settings of header row.

How to do it?
Thanks.

Nov 29 '05 #4
Thanks.
It can work.
"Lenard Gunda" wrote:

Here is a code for an item data bound event handler, I think this should
work :)

private void DataGrid1_ItemDataBound(
object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
// check that item is header
if ( e.Item.ItemType == ListItemType.Header )
{
// check that we have cells
if ( e.Item.Cells.Count > 0 )
{
e.Item.Cells[0].BackColor = Color.Green;
}
}
}

This should run when data is bound to the grid. If checks if the item is
a header item, and if it is, checks if there are any cells. If then
changes the backcolor of that cell. You can also access almost anything
in the DataGrid in a similar way, after it has been built (data bound).

Columns count can be 0, if you use automatic column creation. In that
case, the columns are automatically created for you, but are never added
to the Columns collection itself.

-Lenard
Grace wrote:
I write as following:
DataGrid dg=(DataGrid)obj;
dg.Columns[0].HeaderStyle.BackColor=Color.Green;

but it shows error message.
I check dg.Columns.Count, it is always 0.

Could you write some codes to teach me how to solve it?
Thanks.

"Lenard Gunda" wrote:

Hi,

You could add an ItemDataBound event to the DataGrid. Then, in the event
handler, check when you get a header type of an item. Get the first
column, and change the color programatically.

-Lenard
Grace wrote:

I use a datagrid included in a repeater.

as following: (.aspx)
<asp:repeater id="rp_perform" Runat="server">
<HeaderTemplate>
<table border="0" bgcolor="gray" cellspacing="0" cellpadding="0">
</HeaderTemplate>
<ItemTemplate>
<tr bgcolor="white">
<td width="100%">
<asp:datagrid id="dg_perform" Runat="server" DataSource='<%#
GetDataTable((int)DataBinder.Eval(Container.Dat aItem, "Product_No")) %>'
AutoGenerateColumns="True" GridLines="Both" BorderColor="DimGray"
BorderWidth="2" CellPadding="3" CellSpacing="0">
<HeaderStyle BackColor="#99ccff" Font-Bold="True" />
<ItemStyle BackColor="#FFFFCC" />
</asp:datagrid>
</td>
</tr>
</ItemTemplate>
<SeparatorTemplate>
<tr>
<td height="25" bgcolor="white"></td>
</tr>
</SeparatorTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:repeater>

I want to change first column's backcolor of header row in each datagrid.
I catch every datagrid, it can set item's settings, but can't set first
column's settings of header row.

How to do it?
Thanks.

Nov 29 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Randy Harris | last post: by
5 posts views Thread by objectref | last post: by
2 posts views Thread by David Veeneman | last post: by
reply views Thread by Demetri | last post: by
3 posts views Thread by Hans Merkl | last post: by
3 posts views Thread by Carl Tribble | last post: by
3 posts views Thread by TPhelps | last post: by
4 posts views Thread by Yin99 | last post: by
reply views Thread by Ronak mishra | last post: by

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.