Solved

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

Posted on 2008-10-15
3
220 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
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…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

739 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