Solved

ON ROW DATA BOUND ISSUE

Posted on 2011-09-22
7
187 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
  • 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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
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…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

743 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

12 Experts available now in Live!

Get 1:1 Help Now