Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2008-10-15
3
Medium Priority
?
225 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 2000 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

722 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