473,379 Members | 1,386 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,379 software developers and data experts.

Empty DataGrid Formatting

Hi - I have a datagrid that has a black header and the rows alternate
white and gray. The problem is that until items are added to the grid,
the grid appears as a large black rectangle, which is quite ugly. The
black area is larger then it is once an item is added. How can I solve
this problem either by:
A) Having only the header black and the rest of the empty block white or
gray (preffered solution)
B) Having the color gray or white until an item is added and then
changing to my default template colors - this is less ideal since I
would aslo then have to keep track of if all times are deleted and I go
back to the empty state.

thanks!

Nov 17 '05 #1
7 4656
I believe you go into the Property Builder if it's an ASP.NET grid and
explicitily set the Header height....
"Matthew Wieder" <De*********@SatoriGroupInc.com> wrote in message
news:Ov**************@TK2MSFTNGP09.phx.gbl...
Hi - I have a datagrid that has a black header and the rows alternate
white and gray. The problem is that until items are added to the grid,
the grid appears as a large black rectangle, which is quite ugly. The
black area is larger then it is once an item is added. How can I solve
this problem either by:
A) Having only the header black and the rest of the empty block white or
gray (preffered solution)
B) Having the color gray or white until an item is added and then
changing to my default template colors - this is less ideal since I
would aslo then have to keep track of if all times are deleted and I go
back to the empty state.

thanks!

Nov 17 '05 #2
I'm not sure what version of VS you're using, but in mine, property
builder doesn't allow setting of the height for the header...
anyone else?

alien2_51 wrote:
I believe you go into the Property Builder if it's an ASP.NET grid and
explicitily set the Header height....
"Matthew Wieder" <De*********@SatoriGroupInc.com> wrote in message
news:Ov**************@TK2MSFTNGP09.phx.gbl...
Hi - I have a datagrid that has a black header and the rows alternate
white and gray. The problem is that until items are added to the grid,
the grid appears as a large black rectangle, which is quite ugly. The
black area is larger then it is once an item is added. How can I solve
this problem either by:
A) Having only the header black and the rest of the empty block white or
gray (preffered solution)
B) Having the color gray or white until an item is added and then
changing to my default template colors - this is less ideal since I
would aslo then have to keep track of if all times are deleted and I go
back to the empty state.

thanks!



Nov 17 '05 #3
Hello Matthew,

Thanks for posting in the group.

1) for changing header color:
we could use the following in design time:
<asp:DataGrid ID="DefaultGrid" Runat="server" ShowHeader=True>
<HeaderStyle Font-Size="14px" Font-Bold="True" BackColor="LightSalmon"></HeaderStyle>
</asp:DataGrid>

2) for row colors:
we could implement the ItemDataBound event for the datagrid.

// event code
private void dGrid_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e) {
// only apply on item and alternating item
if (e.Item.ItemType == ListItemType.Item ||
e.Item.ItemType == ListItemType.AlternatingItem)
{
// getting the index value ( or any other data cell
value )
string sVal = e.Item.Cells[0].Text;

// changing the color or all even rows
if ((Convert.ToInt32(sVal) == 3)
{
e.Item.BackColor = System.Drawing.Color.Red;
}
}
}

You can try this also:
After binding the dataset to the datagrid.
just try this piece of code:
datagrid1.items[3].BackColor=System.Drawing.Color.Red.

Hope it helps.

Best regards,
Yanhong Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
!Date: Tue, 12 Aug 2003 11:32:21 -0400
!From: Matthew Wieder <De*********@SatoriGroupInc.com>
!User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)
!X-Accept-Language: en-us, en, he
!MIME-Version: 1.0
!Subject: Re: Empty DataGrid Formatting
!References: <Ov**************@TK2MSFTNGP09.phx.gbl> <#r**************@TK2MSFTNGP12.phx.gbl>
!In-Reply-To: <#r**************@TK2MSFTNGP12.phx.gbl>
!Content-Type: text/plain; charset=us-ascii; format=flowed
!Content-Transfer-Encoding: 7bit
!Message-ID: <uB*************@TK2MSFTNGP10.phx.gbl>
!Newsgroups: microsoft.public.dotnet.framework.aspnet
!NNTP-Posting-Host: 207.106.112.178
!Lines: 1
!Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP10.phx.gbl
!Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet:167121
!X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
!
!I'm not sure what version of VS you're using, but in mine, property
!builder doesn't allow setting of the height for the header...
!anyone else?
!
!alien2_51 wrote:
!
!> I believe you go into the Property Builder if it's an ASP.NET grid and
!> explicitily set the Header height....
!>
!>
!> "Matthew Wieder" <De*********@SatoriGroupInc.com> wrote in message
!> news:Ov**************@TK2MSFTNGP09.phx.gbl...
!>
!>>Hi - I have a datagrid that has a black header and the rows alternate
!>>white and gray. The problem is that until items are added to the grid,
!>>the grid appears as a large black rectangle, which is quite ugly. The
!>>black area is larger then it is once an item is added. How can I solve
!>>this problem either by:
!>>A) Having only the header black and the rest of the empty block white or
!>>gray (preffered solution)
!>>B) Having the color gray or white until an item is added and then
!>>changing to my default template colors - this is less ideal since I
!>>would aslo then have to keep track of if all times are deleted and I go
!>>back to the empty state.
!>>
!>>thanks!
!>>
!>
!>
!>
!
!
Nov 17 '05 #4
I'm not sure you understand the issue - when an ASP.NET datagrid is
empty, whatever background color set for the header "spreads" to the
whole rectange, much larger then the area the header oocupies once it
has data. I'd like a way to stop the "spreading" so that the header
color is not over-applied to an empty grid.

Yan-Hong Huang[MSFT] wrote:
Hello Matthew,

Thanks for posting in the group.

1) for changing header color:
we could use the following in design time:
<asp:DataGrid ID="DefaultGrid" Runat="server" ShowHeader=True>
<HeaderStyle Font-Size="14px" Font-Bold="True" BackColor="LightSalmon"></HeaderStyle>
</asp:DataGrid>

2) for row colors:
we could implement the ItemDataBound event for the datagrid.

// event code
private void dGrid_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e) {
// only apply on item and alternating item
if (e.Item.ItemType == ListItemType.Item ||
e.Item.ItemType == ListItemType.AlternatingItem)
{
// getting the index value ( or any other data cell
value )
string sVal = e.Item.Cells[0].Text;

// changing the color or all even rows
if ((Convert.ToInt32(sVal) == 3)
{
e.Item.BackColor = System.Drawing.Color.Red;
}
}
}

You can try this also:
After binding the dataset to the datagrid.
just try this piece of code:
datagrid1.items[3].BackColor=System.Drawing.Color.Red.

Hope it helps.

Best regards,
Yanhong Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
!Date: Tue, 12 Aug 2003 11:32:21 -0400
!From: Matthew Wieder <De*********@SatoriGroupInc.com>
!User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)
!X-Accept-Language: en-us, en, he
!MIME-Version: 1.0
!Subject: Re: Empty DataGrid Formatting
!References: <Ov**************@TK2MSFTNGP09.phx.gbl> <#r**************@TK2MSFTNGP12.phx.gbl>
!In-Reply-To: <#r**************@TK2MSFTNGP12.phx.gbl>
!Content-Type: text/plain; charset=us-ascii; format=flowed
!Content-Transfer-Encoding: 7bit
!Message-ID: <uB*************@TK2MSFTNGP10.phx.gbl>
!Newsgroups: microsoft.public.dotnet.framework.aspnet
!NNTP-Posting-Host: 207.106.112.178
!Lines: 1
!Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP10.phx.gbl
!Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet:167121
!X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
!
!I'm not sure what version of VS you're using, but in mine, property
!builder doesn't allow setting of the height for the header...
!anyone else?
!
!alien2_51 wrote:
!
!> I believe you go into the Property Builder if it's an ASP.NET grid and
!> explicitily set the Header height....
!>
!>
!> "Matthew Wieder" <De*********@SatoriGroupInc.com> wrote in message
!> news:Ov**************@TK2MSFTNGP09.phx.gbl...
!>
!>>Hi - I have a datagrid that has a black header and the rows alternate
!>>white and gray. The problem is that until items are added to the grid,
!>>the grid appears as a large black rectangle, which is quite ugly. The
!>>black area is larger then it is once an item is added. How can I solve
!>>this problem either by:
!>>A) Having only the header black and the rest of the empty block white or
!>>gray (preffered solution)
!>>B) Having the color gray or white until an item is added and then
!>>changing to my default template colors - this is less ideal since I
!>>would aslo then have to keep track of if all times are deleted and I go
!>>back to the empty state.
!>>
!>>thanks!
!>>
!>
!>
!>
!
!


Nov 17 '05 #5
Ram
Matthew,

Correct me if I could not understand your problem properly.

When you don't have any data in the datagrid, your header is spreading
to the size of the datagrid.

To get rid of this remove the height in the datagrid properties. By
doing this, your datagrid will stretch to the required height,
depending on the data.

If you wan to have fixed datagrid height, rap it in DIV tags and
specify height for the DIV tag.

Hope this helps.
Ram

Matthew Wieder <De*********@SatoriGroupInc.com> wrote in message news:<3F**************@SatoriGroupInc.com>...
I'm not sure you understand the issue - when an ASP.NET datagrid is
empty, whatever background color set for the header "spreads" to the
whole rectange, much larger then the area the header oocupies once it
has data. I'd like a way to stop the "spreading" so that the header
color is not over-applied to an empty grid.

Yan-Hong Huang[MSFT] wrote:
Hello Matthew,

Thanks for posting in the group.

1) for changing header color:
we could use the following in design time:
<asp:DataGrid ID="DefaultGrid" Runat="server" ShowHeader=True>
<HeaderStyle Font-Size="14px" Font-Bold="True" BackColor="LightSalmon"></HeaderStyle>
</asp:DataGrid>

2) for row colors:
we could implement the ItemDataBound event for the datagrid.

// event code
private void dGrid_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e) {
// only apply on item and alternating item
if (e.Item.ItemType == ListItemType.Item ||
e.Item.ItemType == ListItemType.AlternatingItem)
{
// getting the index value ( or any other data cell
value )
string sVal = e.Item.Cells[0].Text;

// changing the color or all even rows
if ((Convert.ToInt32(sVal) == 3)
{
e.Item.BackColor = System.Drawing.Color.Red;
}
}
}

You can try this also:
After binding the dataset to the datagrid.
just try this piece of code:
datagrid1.items[3].BackColor=System.Drawing.Color.Red.

Hope it helps.

Best regards,
Yanhong Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
!Date: Tue, 12 Aug 2003 11:32:21 -0400
!From: Matthew Wieder <De*********@SatoriGroupInc.com>
!User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)
!X-Accept-Language: en-us, en, he
!MIME-Version: 1.0
!Subject: Re: Empty DataGrid Formatting
!References: <Ov**************@TK2MSFTNGP09.phx.gbl> <#r**************@TK2MSFTNGP12.phx.gbl>
!In-Reply-To: <#r**************@TK2MSFTNGP12.phx.gbl>
!Content-Type: text/plain; charset=us-ascii; format=flowed
!Content-Transfer-Encoding: 7bit
!Message-ID: <uB*************@TK2MSFTNGP10.phx.gbl>
!Newsgroups: microsoft.public.dotnet.framework.aspnet
!NNTP-Posting-Host: 207.106.112.178
!Lines: 1
!Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP10.phx.gbl
!Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet:167121
!X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
!
!I'm not sure what version of VS you're using, but in mine, property
!builder doesn't allow setting of the height for the header...
!anyone else?
!
!alien2_51 wrote:
!
!> I believe you go into the Property Builder if it's an ASP.NET grid and
!> explicitily set the Header height....
!>
!>
!> "Matthew Wieder" <De*********@SatoriGroupInc.com> wrote in message
!> news:Ov**************@TK2MSFTNGP09.phx.gbl...
!>
!>>Hi - I have a datagrid that has a black header and the rows alternate
!>>white and gray. The problem is that until items are added to the grid,
!>>the grid appears as a large black rectangle, which is quite ugly. The
!>>black area is larger then it is once an item is added. How can I solve
!>>this problem either by:
!>>A) Having only the header black and the rest of the empty block white or
!>>gray (preffered solution)
!>>B) Having the color gray or white until an item is added and then
!>>changing to my default template colors - this is less ideal since I
!>>would aslo then have to keep track of if all times are deleted and I go
!>>back to the empty state.
!>>
!>>thanks!
!>>
!>
!>
!>
!
!

Nov 17 '05 #6
Hello Matthew,

Now I understand what you need now. :) Ram is right. If we don't set
DataGrid's Height property, the height of the header row will return to
normal. I have tested it on my side and it looks nice now.

If you have follow up questions, please post here. Thanks very much.

Best regards,
Yanhong Huang
Microsoft Online Partner Support

Get Secure! ¨C www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
!Message-ID: <3F**************@SatoriGroupInc.com>
!Date: Wed, 13 Aug 2003 13:38:40 -0400
!From: Matthew Wieder <De*********@SatoriGroupInc.com>
!User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.4)
Gecko/20030624 Netscape/7.1 (ax)
!X-Accept-Language: en-us, en, he
!MIME-Version: 1.0
!To: "Yan-Hong Huang[MSFT]" <yh*****@online.microsoft.com>
!Subject: Re: Empty DataGrid Formatting
!References: <Ov**************@TK2MSFTNGP09.phx.gbl>
<#r**************@TK2MSFTNGP12.phx.gbl>
<uB*************@TK2MSFTNGP10.phx.gbl>
<5n**************@cpmsftngxa06.phx.gbl>
!In-Reply-To: <5n**************@cpmsftngxa06.phx.gbl>
!Content-Type: text/plain; charset=us-ascii; format=flowed
!Content-Transfer-Encoding: 7bit
!Newsgroups: microsoft.public.dotnet.framework.aspnet
!NNTP-Posting-Host: 207.106.112.178
!Lines: 1
!Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP10.phx.gbl
!Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet:167586
!X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
!
!I'm not sure you understand the issue - when an ASP.NET datagrid is
!empty, whatever background color set for the header "spreads" to the
!whole rectange, much larger then the area the header oocupies once it
!has data. I'd like a way to stop the "spreading" so that the header
!color is not over-applied to an empty grid.
!
!Yan-Hong Huang[MSFT] wrote:
!
!> Hello Matthew,
!>
!> Thanks for posting in the group.
!>
!> 1) for changing header color:
!> we could use the following in design time:
!> <asp:DataGrid ID="DefaultGrid" Runat="server" ShowHeader=True>
!> <HeaderStyle Font-Size="14px" Font-Bold="True"
BackColor="LightSalmon"></HeaderStyle>
!> </asp:DataGrid>
!>
!> 2) for row colors:
!> we could implement the ItemDataBound event for the datagrid.
!>
!> // event code
!> private void dGrid_ItemDataBound(object sender,
!> System.Web.UI.WebControls.DataGridItemEventArgs e) {
!> // only apply on item and alternating item
!> if (e.Item.ItemType == ListItemType.Item ||
!> e.Item.ItemType == ListItemType.AlternatingItem)
!> {
!> // getting the index value ( or any other data cell
!> value )
!> string sVal = e.Item.Cells[0].Text;
!>
!> // changing the color or all even rows
!> if ((Convert.ToInt32(sVal) == 3)
!> {
!> e.Item.BackColor = System.Drawing.Color.Red;
!> }
!> }
!> }
!>
!> You can try this also:
!> After binding the dataset to the datagrid.
!> just try this piece of code:
!> datagrid1.items[3].BackColor=System.Drawing.Color.Red.
!>
!> Hope it helps.
!>
!> Best regards,
!> Yanhong Huang
!> Microsoft Online Partner Support
!>
!> Get Secure! - www.microsoft.com/security
!> This posting is provided "AS IS" with no warranties, and confers no
rights.
!>
!> --------------------
!> !Date: Tue, 12 Aug 2003 11:32:21 -0400
!> !From: Matthew Wieder <De*********@SatoriGroupInc.com>
!> !User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.4)
Gecko/20030624 Netscape/7.1 (ax)
!> !X-Accept-Language: en-us, en, he
!> !MIME-Version: 1.0
!> !Subject: Re: Empty DataGrid Formatting
!> !References: <Ov**************@TK2MSFTNGP09.phx.gbl>
<#r**************@TK2MSFTNGP12.phx.gbl>
!> !In-Reply-To: <#r**************@TK2MSFTNGP12.phx.gbl>
!> !Content-Type: text/plain; charset=us-ascii; format=flowed
!> !Content-Transfer-Encoding: 7bit
!> !Message-ID: <uB*************@TK2MSFTNGP10.phx.gbl>
!> !Newsgroups: microsoft.public.dotnet.framework.aspnet
!> !NNTP-Posting-Host: 207.106.112.178
!> !Lines: 1
!> !Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP10.phx.gbl
!> !Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.aspnet:167121
!> !X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
!> !
!> !I'm not sure what version of VS you're using, but in mine, property
!> !builder doesn't allow setting of the height for the header...
!> !anyone else?
!> !
!> !alien2_51 wrote:
!> !
!> !> I believe you go into the Property Builder if it's an ASP.NET grid and
!> !> explicitily set the Header height....
!> !>
!> !>
!> !> "Matthew Wieder" <De*********@SatoriGroupInc.com> wrote in message
!> !> news:Ov**************@TK2MSFTNGP09.phx.gbl...
!> !>
!> !>>Hi - I have a datagrid that has a black header and the rows alternate
!> !>>white and gray. The problem is that until items are added to the
grid,
!> !>>the grid appears as a large black rectangle, which is quite ugly. The
!> !>>black area is larger then it is once an item is added. How can I
solve
!> !>>this problem either by:
!> !>>A) Having only the header black and the rest of the empty block white
or
!> !>>gray (preffered solution)
!> !>>B) Having the color gray or white until an item is added and then
!> !>>changing to my default template colors - this is less ideal since I
!> !>>would aslo then have to keep track of if all times are deleted and I
go
!> !>>back to the empty state.
!> !>>
!> !>>thanks!
!> !>>
!> !>
!> !>
!> !>
!> !
!> !
!>
!>
!
!

Nov 17 '05 #7
Hello Matthew,

You are welcome. If you have follow up questions, please feel free to post in the group and we are glad to be of assistance.

Thanks very much for participating the community.

Best regards,
Yanhong Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
!Date: Thu, 14 Aug 2003 08:56:44 -0400
!From: Matthew Wieder <De*********@SatoriGroupInc.com>
!User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)
!X-Accept-Language: en-us, en, he
!MIME-Version: 1.0
!Subject: Re: Empty DataGrid Formatting
!References: <Ov**************@TK2MSFTNGP09.phx.gbl> <#r**************@TK2MSFTNGP12.phx.gbl>
<uB*************@TK2MSFTNGP10.phx.gbl> <5n**************@cpmsftngxa06.phx.gbl> <3F3A77A0.1000308
@SatoriGroupInc.com> <p#**************@cpmsftngxa06.phx.gbl>
!In-Reply-To: <p#**************@cpmsftngxa06.phx.gbl>
!Content-Type: text/plain; charset=ISO-8859-1; format=flowed
!Content-Transfer-Encoding: 8bit
!Message-ID: <#8**************@TK2MSFTNGP10.phx.gbl>
!Newsgroups: microsoft.public.dotnet.framework.aspnet
!NNTP-Posting-Host: 207.106.112.178
!Lines: 1
!Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP10.phx.gbl
!Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet:167845
!X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
!
!Thanks!
!
!Yan-Hong Huang[MSFT] wrote:
!> Hello Matthew,
!>
!> Now I understand what you need now. :) Ram is right. If we don't set
!> DataGrid's Height property, the height of the header row will return to
!> normal. I have tested it on my side and it looks nice now.
!>
!> If you have follow up questions, please post here. Thanks very much.
!>
!> Best regards,
!> Yanhong Huang
!> Microsoft Online Partner Support
!>
!> Get Secure! ¨C www.microsoft.com/security
!> This posting is provided "AS IS" with no warranties, and confers no rights.
!>
!> --------------------
!> !Message-ID: <3F**************@SatoriGroupInc.com>
!> !Date: Wed, 13 Aug 2003 13:38:40 -0400
!> !From: Matthew Wieder <De*********@SatoriGroupInc.com>
!> !User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.4)
!> Gecko/20030624 Netscape/7.1 (ax)
!> !X-Accept-Language: en-us, en, he
!> !MIME-Version: 1.0
!> !To: "Yan-Hong Huang[MSFT]" <yh*****@online.microsoft.com>
!> !Subject: Re: Empty DataGrid Formatting
!> !References: <Ov**************@TK2MSFTNGP09.phx.gbl>
!> <#r**************@TK2MSFTNGP12.phx.gbl>
!> <uB*************@TK2MSFTNGP10.phx.gbl>
!> <5n**************@cpmsftngxa06.phx.gbl>
!> !In-Reply-To: <5n**************@cpmsftngxa06.phx.gbl>
!> !Content-Type: text/plain; charset=us-ascii; format=flowed
!> !Content-Transfer-Encoding: 7bit
!> !Newsgroups: microsoft.public.dotnet.framework.aspnet
!> !NNTP-Posting-Host: 207.106.112.178
!> !Lines: 1
!> !Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP10.phx.gbl
!> !Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet:167586
!> !X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
!> !
!> !I'm not sure you understand the issue - when an ASP.NET datagrid is
!> !empty, whatever background color set for the header "spreads" to the
!> !whole rectange, much larger then the area the header oocupies once it
!> !has data. I'd like a way to stop the "spreading" so that the header
!> !color is not over-applied to an empty grid.
!> !
!> !Yan-Hong Huang[MSFT] wrote:
!> !
!> !> Hello Matthew,
!> !>
!> !> Thanks for posting in the group.
!> !>
!> !> 1) for changing header color:
!> !> we could use the following in design time:
!> !> <asp:DataGrid ID="DefaultGrid" Runat="server" ShowHeader=True>
!> !> <HeaderStyle Font-Size="14px" Font-Bold="True"
!> BackColor="LightSalmon"></HeaderStyle>
!> !> </asp:DataGrid>
!> !>
!> !> 2) for row colors:
!> !> we could implement the ItemDataBound event for the datagrid.
!> !>
!> !> // event code
!> !> private void dGrid_ItemDataBound(object sender,
!> !> System.Web.UI.WebControls.DataGridItemEventArgs e) {
!> !> // only apply on item and alternating item
!> !> if (e.Item.ItemType == ListItemType.Item ||
!> !> e.Item.ItemType == ListItemType.AlternatingItem)
!> !> {
!> !> // getting the index value ( or any other data cell
!> !> value )
!> !> string sVal = e.Item.Cells[0].Text;
!> !>
!> !> // changing the color or all even rows
!> !> if ((Convert.ToInt32(sVal) == 3)
!> !> {
!> !> e.Item.BackColor = System.Drawing.Color.Red;
!> !> }
!> !> }
!> !> }
!> !>
!> !> You can try this also:
!> !> After binding the dataset to the datagrid.
!> !> just try this piece of code:
!> !> datagrid1.items[3].BackColor=System.Drawing.Color.Red.
!> !>
!> !> Hope it helps.
!> !>
!> !> Best regards,
!> !> Yanhong Huang
!> !> Microsoft Online Partner Support
!> !>
!> !> Get Secure! - www.microsoft.com/security
!> !> This posting is provided "AS IS" with no warranties, and confers no
!> rights.
!> !>
!> !> --------------------
!> !> !Date: Tue, 12 Aug 2003 11:32:21 -0400
!> !> !From: Matthew Wieder <De*********@SatoriGroupInc.com>
!> !> !User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.4)
!> Gecko/20030624 Netscape/7.1 (ax)
!> !> !X-Accept-Language: en-us, en, he
!> !> !MIME-Version: 1.0
!> !> !Subject: Re: Empty DataGrid Formatting
!> !> !References: <Ov**************@TK2MSFTNGP09.phx.gbl>
!> <#r**************@TK2MSFTNGP12.phx.gbl>
!> !> !In-Reply-To: <#r**************@TK2MSFTNGP12.phx.gbl>
!> !> !Content-Type: text/plain; charset=us-ascii; format=flowed
!> !> !Content-Transfer-Encoding: 7bit
!> !> !Message-ID: <uB*************@TK2MSFTNGP10.phx.gbl>
!> !> !Newsgroups: microsoft.public.dotnet.framework.aspnet
!> !> !NNTP-Posting-Host: 207.106.112.178
!> !> !Lines: 1
!> !> !Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP10.phx.gbl
!> !> !Xref: cpmsftngxa06.phx.gbl
!> microsoft.public.dotnet.framework.aspnet:167121
!> !> !X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
!> !> !
!> !> !I'm not sure what version of VS you're using, but in mine, property
!> !> !builder doesn't allow setting of the height for the header...
!> !> !anyone else?
!> !> !
!> !> !alien2_51 wrote:
!> !> !
!> !> !> I believe you go into the Property Builder if it's an ASP.NET grid and
!> !> !> explicitily set the Header height....
!> !> !>
!> !> !>
!> !> !> "Matthew Wieder" <De*********@SatoriGroupInc.com> wrote in message
!> !> !> news:Ov**************@TK2MSFTNGP09.phx.gbl...
!> !> !>
!> !> !>>Hi - I have a datagrid that has a black header and the rows alternate
!> !> !>>white and gray. The problem is that until items are added to the
!> grid,
!> !> !>>the grid appears as a large black rectangle, which is quite ugly. The
!> !> !>>black area is larger then it is once an item is added. How can I
!> solve
!> !> !>>this problem either by:
!> !> !>>A) Having only the header black and the rest of the empty block white
!> or
!> !> !>>gray (preffered solution)
!> !> !>>B) Having the color gray or white until an item is added and then
!> !> !>>changing to my default template colors - this is less ideal since I
!> !> !>>would aslo then have to keep track of if all times are deleted and I
!> go
!> !> !>>back to the empty state.
!> !> !>>
!> !> !>>thanks!
!> !> !>>
!> !> !>
!> !> !>
!> !> !>
!> !> !
!> !> !
!> !>
!> !>
!> !
!> !
!>
!
!
Nov 17 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jim | last post by:
In my Win App, I have a datagrid that's bound to a dataset. When the form loads, the datagrid fills. How can I add an empty row to the end of the datagrid during a button click (similar to...
0
by: Frnak McKenney | last post by:
One of the reasons given for the Allied victory in WWI is that the Nazi armament industry invested so much effort in creating new weapons (e.g. the jet plane) it wasn't able to develop any of them...
1
by: J.B | last post by:
I have a datagrid that will display different datasets, (it runs different sprocs based on a value in the querystring) but it will always return 6 columns. The 5th and 6th columns are always Date...
3
by: McNutt Consulting | last post by:
I'm trying to implement a datagrid with dynamically created columns. The data is coming out of a very simple XML file, and it's bound through a dataview. The datagrid is just a shell definition...
5
by: tshad | last post by:
I have been trying to figure out what the Datagrid is doing to create its formatting. I found that some of my Datagrids have a 3D type of border and sometime it has a straight line. I finally...
2
by: carballosa | last post by:
Hi guys, I need to use a one row datagrid in my asp.net 1.1 application. The data source will contain 1 or 0 entries. When no rows of data are present I want to show an empty row in the datagrid...
5
by: cwbp17 | last post by:
Hi all, Have a datagrid that displays the price column of a table. Went to the Datagrid's Property builder and set the 'Data Formatting expression' for the PRICE column to {0:c}, so that the...
4
by: hope | last post by:
Hi, How can I format a string field using Data Formatting Expression property in datagrid? For example: format last name from BROWN to Brown. Thanks
1
by: Michael Calvin | last post by:
Some basic things I cannot figure out how to do with new datagrid. 1) How do I control the formatting of the column header separately from the rest of the column? 2) If I align right the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.