Solved

ON ROW DATA BOUND ISSUE

Posted on 2011-09-22
7
203 Views
Last Modified: 2012-05-12
I have the attached gridview which I want to change the row color when a certain condition exists in column "Status1" = "AOG".   The onrowdatabound event does not seem to be firing.  Any assistance with the code would be appreciated.
<asp:GridView runat="server" id="GridView1" AutoGenerateColumns="False" DataSourceID="AccessDataSource1" onrowdatabound="GridView1_RowDataBound" DataKeyNames="ID" AllowSorting="True" Font-Size="Small" Font-Names="Arial" ShowFooter="True" HorizontalAlign="Center">
<RowStyle HorizontalAlign="Center" BackColor="White" ForeColor="Black" Width="1300px" />

<Columns>

Open in new window

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Home1All : System.Web.UI.Page
{
    protected void GridView1_OnRowDataBound(object sender, GridViewRowEventArgs e)
    {

        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if (Convert.ToString(DataBinder.Eval(e.Row.DataItem, "Status1")) == "AOG")
            {
                e.Row.BackColor = System.Drawing.Color.Red;
            }
            else
            {
                e.Row.ForeColor = System.Drawing.Color.Yellow;

            }
        }
    }
}

Open in new window

0
Comment
Question by:BOEING39
[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
  • 3
  • 3
7 Comments
 
LVL 26

Expert Comment

by:Anurag Thakur
ID: 36584878
try calling the gridview.databind() method and hopefully then your events might fire
http://forums.asp.net/t/1048369.aspx/1
0
 

Author Comment

by:BOEING39
ID: 36584978
No help......
0
 
LVL 12

Expert Comment

by:Ramkisan Jagtap
ID: 36585188
Hi,
When are you calling your gridview.databind() method?
If you are calling on Page_Load(), Call it in !IsPostBack i.e.

Page_Load()
{
                    if(!IsPostBack)
                     {
                                //Here you gridview bindung code comes.
                      }
}

Regards,
Ram
0
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!

 

Author Comment

by:BOEING39
ID: 36587669
Can you assist in the placement of the page Load Event and data bind method code placement.   I an very new to this.....  

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Home1All : System.Web.UI.Page
{
    protected void GridView1_OnRowDataBound(object sender, GridViewRowEventArgs e)
    {

        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if (Convert.ToString(DataBinder.Eval(e.Row.DataItem, "Status1")) == "AOG")
            {
                e.Row.BackColor = System.Drawing.Color.Red;
            }
            else
            {
                e.Row.ForeColor = System.Drawing.Color.Yellow;

            }
        }
    }
}

Open in new window

0
 
LVL 12

Accepted Solution

by:
Ramkisan Jagtap earned 500 total points
ID: 36591934

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Home1All : System.Web.UI.Page
{

     protected void Page_Load(object sender, EventArgs e)
     {
              if(!IsPostBack)
                     {
                           GridView1.DataSource= GetdataSource();//GetDataSource is the Method which returns datsource for your griedview
                           GridView1.DataBind():
                      }
     }
    protected void GridView1_OnRowDataBound(object sender, GridViewRowEventArgs e)
    {

        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if (Convert.ToString(DataBinder.Eval(e.Row.DataItem, "Status1")) == "AOG")
            {
                e.Row.BackColor = System.Drawing.Color.Red;
            }
            else
            {
                e.Row.ForeColor = System.Drawing.Color.Yellow;

            }
        }
    }
}

Open in new window

0
 
LVL 12

Expert Comment

by:Ramkisan Jagtap
ID: 36591940
Hope this will help you.

Regards,
Ram
0
 

Author Closing Comment

by:BOEING39
ID: 36593584
That did it.  Thx
0

Featured Post

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

705 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