Solved

Change text in Gridview to different text

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

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 …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now