Solved

Change text in Gridview to different text

Posted on 2014-12-16
4
105 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
  • 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

810 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