Solved

ON ROW DATA BOUND ISSUE

Posted on 2011-09-22
7
194 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Runtime Exceptions when trying to submit data 28 37
Export import database 4 45
Code works but it's slow 24 47
Finally almost got it 5 23
Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

863 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

23 Experts available now in Live!

Get 1:1 Help Now