Solved

Change text in Gridview to different text

Posted on 2014-12-16
4
109 Views
Last Modified: 2014-12-17
One of the columns in my gridview return either a "o" or an "s". I want to be able to have the grid show either "Open" or "Started". Any ideas? I went ahead and started by creating the template field. Please help me fill in the blanks.

<asp:TemplateField HeaderText="Status">
                <ItemTemplate>
                    <asp:Label ID="lblStatus" runat="server" Text='<%# Eval("Expr1")%>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>

Open in new window


Please give me code in c#.
0
Comment
Question by:princeservice
[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
  • 2
  • 2
4 Comments
 

Author Comment

by:princeservice
ID: 40504006
I tried this but it does not work.

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow) {
            if (e.Row.Cells[9].Text == "O")
            { e.Row.Cells[9].Text = "Open"; }
        }
       
    }

Open in new window

0
 
LVL 35

Expert Comment

by:Robert Schutt
ID: 40504402
Do you really need the label that you create with the TemplateField? If you use a BoundField instead, then your code works:
<asp:BoundField DataField="Expr1" HeaderText="Status" />

Open in new window

If you do need the template I think you will have to access the data source instead of e.Row.
0
 
LVL 35

Accepted Solution

by:
Robert Schutt earned 500 total points
ID: 40504474
Actually, found the solution for your current markup, with TemplateField and label:
        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) {
            if (e.Row.RowType == DataControlRowType.DataRow) {
                Label lbl = (Label)e.Row.FindControl("lblStatus");
                if (lbl.Text == "O") { lbl.Text = "Open"; }
            }
        }

Open in new window

0
 

Author Closing Comment

by:princeservice
ID: 40504827
You're awesome
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

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…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

728 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