Solved

RowDataBound is not revealing the cells text contents now that it is a templatefield (Probably Easy)

Posted on 2008-10-15
3
217 Views
Last Modified: 2012-06-21
I had this simple event procedure which turned row colour when certain values were detected.
All was fine until I converted the column concerned to a template field, now the e.Row.Cells(2).Text always returns a blank.  What do I need to do to inspect this field again?

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
            Select Case e.Row.Cells(2).Text
                Case "1. Starting"
                    e.Row.BackColor = System.Drawing.Color.Orange
                Case "2. Current"
                Case "3. Finishing"
                    e.Row.BackColor = System.Drawing.Color.PaleVioletRed
                Case "4. Finished"
            End Select
        End If
    End Sub
0
Comment
Question by:dgloveruk
3 Comments
 
LVL 20

Accepted Solution

by:
informaniac earned 500 total points
ID: 22719082
You'll have to first to cast the control that u've placed in the templatecolumn and then find it's text.

Dim txt As TextBox = DirectCast(e.Row.FindControl("txtNAme"), TextBox)
0
 
LVL 10

Expert Comment

by:jinn_hnnl
ID: 22719196
Does the color change after you set it?

Just store the current value and assign it after you change that color

Dim currentValue As String
currentValue = e.Row.Cells(2).Text

Select Case e.Row.Cells(2).Text
                Case "1. Starting"
                    e.Row.BackColor = System.Drawing.Color.Orange
                Case "2. Current"
                Case "3. Finishing"
                    e.Row.BackColor = System.Drawing.Color.PaleVioletRed
                Case "4. Finished"
            End Select
e.Row.Cells(2).Text = currentValue;

Give it a try?

0
 

Author Closing Comment

by:dgloveruk
ID: 31506229
This was a great solution, I didn't know about casting before and I can use this for a lot of other stuff! thanks!
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question