?
Solved

Change text in Gridview to different text

Posted on 2014-12-16
4
Medium Priority
?
112 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 2000 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
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…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month15 days, 16 hours left to enroll

741 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