problem with e.Row.Cells() of gridview

C

Chris

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
 
C

Chris

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.
 
C

Chris

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
 
C

Chris

I found it:

i need to use e.Row.Cells(3).FindControl("label1")


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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top