Solved

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

Posted on 2008-10-15
3
214 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
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…

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now