473,397 Members | 2,099 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,397 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 2435
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Randy Harris | last post by:
I can easily select a row in a listbox with: Me.lstMyListBox = "Some Data" if "Some Data" is in a record in the bound column. Is there any way to select a record based on a column other than the...
5
by: objectref | last post by:
Hi to all, i populate a ListView with data from a datareader and i just want to know the column name of the cell that the user clicks on. E.x., if the user clicks on the 2nd column, 3rd row in...
2
by: David Veeneman | last post by:
How can I set a bound DataGridView control to use a dataset table's column captions, instead of column names? I'm working with a DataGridView control, which I have bound to a table in a dataset....
0
by: Demetri | last post by:
I have a web form with a datagrid. The datagrid has 5 columns. In design mode each column has header text. I defined the header text, data source, etc in property builder (visible is checked in...
3
by: Hans Merkl | last post by:
Hi, I was wondering if it's possible to bind the header text of a GridView column to a method of an object I have. At the moment I am setting the header texts in Page_Load but I was wondering if...
3
by: Carl Tribble | last post by:
After a user has clicked a column header to sort, how can I tell which column header he clicked? In other words, how can I tell what order the list is in after user changes it by clicking a column...
2
by: ricky | last post by:
Hello, If anyone could help me with this I would highly appreciate it. I've tried everything and nothing works. What I am trying to do is so damn basic and it's just frustrating that it seems...
3
by: TPhelps | last post by:
I have a sample of an unbound (autogeneratecolumns is true) sortable/pagable datagrid that works. I want to change one of the columns to a hyperlink. The examples I find use a bound column. I...
4
by: Yin99 | last post by:
I have a Gridview binding to a DataTable source. I'd like to set the column with of the second column. I cannot do this apparently because when AutoGenerateColumns=true, they do not appear in the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.