Solved

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

Posted on 2008-10-15
3
219 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Open dialog with server side controls in it 3 46
Generate Unique ID in VB.NET 21 103
ASP.NET Content Page 3 51
Record locking on classic ASP 3 38
Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
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…
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

756 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