Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > problem with e.Row.Cells() of gridview

Reply
Thread Tools

problem with e.Row.Cells() of gridview

 
 
Chris
Guest
Posts: n/a
 
      05-08-2008
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>
<aspropDownList ID="DropDownList1" SelectedValue='<%#
Bind("theday") %>' runat="server">
<asp:ListItem Text="y" Value="y"></asp:ListItem>
<asp:ListItem Text="n" Value="n"></asp:ListItem>
</aspropDownList>
</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


 
Reply With Quote
 
 
 
 
Chris
Guest
Posts: n/a
 
      05-09-2008
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" <(E-Mail Removed)> schreef in bericht
news:%(E-Mail Removed)...
> 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>
> <aspropDownList ID="DropDownList1" SelectedValue='<%#
> Bind("theday") %>' runat="server">
> <asp:ListItem Text="y" Value="y"></asp:ListItem>
> <asp:ListItem Text="n" Value="n"></asp:ListItem>
> </aspropDownList>
> </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
>



 
Reply With Quote
 
 
 
 
Chris
Guest
Posts: n/a
 
      05-09-2008
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]" <(E-Mail Removed)> schreef in bericht
news:%(E-Mail Removed)...
> "Chris" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>
>> 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



 
Reply With Quote
 
Chris
Guest
Posts: n/a
 
      05-09-2008
I found it:

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


Chris" <(E-Mail Removed)> schreef in bericht
news:%(E-Mail Removed)...

> 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]" <(E-Mail Removed)> schreef in bericht
> news:%(E-Mail Removed)...
>> "Chris" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>>
>>> 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

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Gridview inside gridview problem Vik ASP .Net 1 05-11-2009 10:07 PM
GridView RowCommand problem: GridView Nested in Repeater HeavyMetal ASP .Net Web Controls 0 08-08-2006 01:17 PM
GridView Hierarchical View - Gridview in Gridview =?Utf-8?B?bWdvbnphbGVzMw==?= ASP .Net 1 05-09-2006 06:48 PM
GridView in a GridView Nalaka ASP .Net 6 12-05-2005 05:48 PM
Gridview with combobox whose data is dependent on field in gridview wallermj@hotmail.com ASP .Net 3 11-21-2005 05:34 PM



Advertisments