Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Change text in Gridview to different text

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

609 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