BOEING39
asked on
ON ROW DATA BOUND ISSUE
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>
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;
}
}
}
}
ASKER
No help......
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
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
ASKER
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;
}
}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hope this will help you.
Regards,
Ram
Regards,
Ram
ASKER
That did it. Thx
http://forums.asp.net/t/1048369.aspx/1