473,406 Members | 2,273 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,406 software developers and data experts.

problem with e.Row.Cells() of gridview

Hi,

i want to make the forecolor of values into a gridview red but only when
they equals 'n'.

<asp:GridView ID="GridView1" runat="server"
DataKeyNames="hour,place" DataSourceID="SqlDataSource1" >
<Columns>
<asp:CommandField ShowEditButton="True"/>
<asp:BoundField DataField="place" HeaderText="place"
ReadOnly="True" />
<asp:BoundField DataField="hour" HeaderText="hour"
ReadOnly="True" />

<asp:TemplateField HeaderText="theday">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList1" SelectedValue='<%#
Bind("theday") %>' runat="server">
<asp:ListItem Text="y" Value="y"></asp:ListItem>
<asp:ListItem Text="n" Value="n"></asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("theday")
%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>

</Columns>
</asp:GridView>
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewRowEventArgs) Handles
GridView1.RowDataBound

If e.Row.RowType = DataControlRowType.DataRow Then
Dim m As String
m = e.Row.Cells(3).Text
If m = "n" Then
e.Row.Cells(3).ForeColor = Drawing.Color.Red
End If
End If
End Sub

The values are correctly rendered, i can update etc ... but the forecolor
remains black. Is this due to the template?
Thanks for help
Chris
Jun 27 '08 #1
5 5231
I tested with this line:
response.write(e.Row.Cells(3).Text) which gives nothing ....
but, as i wrote, the gridview renders correctly the values.
"Chris" <ss*@qsd.dcschreef in bericht
news:%2****************@TK2MSFTNGP02.phx.gbl...
Hi,

i want to make the forecolor of values into a gridview red but only when
they equals 'n'.

<asp:GridView ID="GridView1" runat="server"
DataKeyNames="hour,place" DataSourceID="SqlDataSource1" >
<Columns>
<asp:CommandField ShowEditButton="True"/>
<asp:BoundField DataField="place" HeaderText="place"
ReadOnly="True" />
<asp:BoundField DataField="hour" HeaderText="hour"
ReadOnly="True" />

<asp:TemplateField HeaderText="theday">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList1" SelectedValue='<%#
Bind("theday") %>' runat="server">
<asp:ListItem Text="y" Value="y"></asp:ListItem>
<asp:ListItem Text="n" Value="n"></asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("theday")
%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>

</Columns>
</asp:GridView>
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewRowEventArgs) Handles
GridView1.RowDataBound

If e.Row.RowType = DataControlRowType.DataRow Then
Dim m As String
m = e.Row.Cells(3).Text
If m = "n" Then
e.Row.Cells(3).ForeColor = Drawing.Color.Red
End If
End If
End Sub

The values are correctly rendered, i can update etc ... but the forecolor
remains black. Is this due to the template?
Thanks for help
Chris

Jun 27 '08 #2
"Chris" <ss*@qsd.dcwrote in message
news:ug**************@TK2MSFTNGP04.phx.gbl...
I tested with this line:
Response.Write(e.Row.Cells(3).Text) which gives nothing ....
Judging by your markup, that would be correct...
but, as I wrote, the GridView renders correctly the values.
No doubt, but not in the way you think.

Please clarify which of the columns in the GridView (you think) corresponds
to e.Row.Cells(3)...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Jun 27 '08 #3
Thanks for replying.
Well, i think that:
e.Row.Cells(0) is the editbutton
e.Row.Cells(1) is field 'place' (tested with response.write)
e.Row.Cells(2) is field 'hour' (tested with response.write)
so e.Row.Cells(3) is field 'theday'

May i know what you think i think?
Thanks
"Mark Rae [MVP]" <ma**@markNOSPAMrae.netschreef in bericht
news:%2****************@TK2MSFTNGP06.phx.gbl...
"Chris" <ss*@qsd.dcwrote in message
news:ug**************@TK2MSFTNGP04.phx.gbl...
>I tested with this line:
Response.Write(e.Row.Cells(3).Text) which gives nothing ....

Judging by your markup, that would be correct...
>but, as I wrote, the GridView renders correctly the values.

No doubt, but not in the way you think.

Please clarify which of the columns in the GridView (you think)
corresponds to e.Row.Cells(3)...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Jun 27 '08 #4
I found it:

i need to use e.Row.Cells(3).FindControl("label1")
Chris" <ss*@qsd.dcschreef in bericht
news:%2****************@TK2MSFTNGP02.phx.gbl...
Thanks for replying.
Well, i think that:
e.Row.Cells(0) is the editbutton
e.Row.Cells(1) is field 'place' (tested with response.write)
e.Row.Cells(2) is field 'hour' (tested with response.write)
so e.Row.Cells(3) is field 'theday'

May i know what you think i think?
Thanks
"Mark Rae [MVP]" <ma**@markNOSPAMrae.netschreef in bericht
news:%2****************@TK2MSFTNGP06.phx.gbl...
>"Chris" <ss*@qsd.dcwrote in message
news:ug**************@TK2MSFTNGP04.phx.gbl...
>>I tested with this line:
Response.Write(e.Row.Cells(3).Text) which gives nothing ....

Judging by your markup, that would be correct...
>>but, as I wrote, the GridView renders correctly the values.

No doubt, but not in the way you think.

Please clarify which of the columns in the GridView (you think)
corresponds to e.Row.Cells(3)...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net


Jun 27 '08 #5
"Chris" <ss*@qsd.dcwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...

[top-posting corrected]
>Please clarify which of the columns in the GridView (you think)
corresponds to e.Row.Cells(3)...
so e.Row.Cells(3) is field 'theday'
You mean this: ?
<asp:Label ID="Label2" runat="server" Text='<%# Bind("theday")
%>'></asp:Label>

If so, then e.Row.Cells(3).Text is always going to return an empty string.

Why? Because the field in question doesn't contain any text. It contains an
<asp:Iabelwebcontrol, which isn't the same thing at all as far as ASP.NET
is concerned...

Try this:

Dim MyLabel As Label = e.Row.Cells(3).FindControl("Label2")
Response.Write(MyLabel.Text)

The syntax may not be 100% correct as I never go anywhere near VB.NET...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Jun 27 '08 #6

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

Similar topics

1
by: bill tie | last post by:
I have two dropDownLists A and B outside a gridView. A selection made in ddlA causes ddlB to be populated with data from the database. The gridView is populated with data according to a...
2
by: Loading name... | last post by:
Hey asp.net 2.0 I have a GridView on my webpage. This GridView's datasource is a SqlDataSource. The SqlDataSource returns 3 columns. Here is my problem: My GridView consist of 3 columns...
3
by: Jeff | last post by:
Hey asp.net 2.0 I got a GridView on my webpage. When I run the webpage and select a row in the GridView, the SelectedIndexChanged event isn't triggered. The row I clicked on isn't marked as...
3
by: Jeff | last post by:
Hey asp.net 2.0 In the source I posted below, there is a GridView (look at the bottom of the script): <asp:GridView ID="gvwOnline" runat="server"> </asp:GridView> I'm trying to assign a...
1
by: Jeff | last post by:
Hey asp.net 2.0 I have this GridView in my web page. My problem is that it get populated with all the fields of the MembershipUser class. I thought only UserName would be displayed, but it...
1
by: Jeff | last post by:
ASP.NET 2.0 I've got problems with the right column in my GridView. The GridView consist of 2 columns, the problem column is the column on the right side. The problem is that it looks like...
3
by: gnewsgroup | last post by:
I have a GridView which is bound to my database. The leftmost column of the GridView has a value of either 0 or 1, and I need to highlight the cell of column 3 if the leftmost column has a...
1
by: thiagarajanrsbe | last post by:
protected void gridReport_RowUpdating(object sender, GridViewUpdateEventArgs e) { try { for (int i = 0; i < gridReport.Columns.Count; i++) { ...
0
by: =?Utf-8?B?UmF5bmFsZA==?= | last post by:
Hi everybody, I have a problem on linq related field, look my simple example : <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <!DOCTYPE html...
1
by: siri11 | last post by:
Hi everyone... I'm developing an application in asp.net with C#.net and Sqlserver as backend connecting to a local server.In one of the web forms the requirement is such that when I select an...
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?
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...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
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.