menu

Monday, May 23, 2011

Grid View Row Color on RewDataBound Event


Grid View:

<asp:GridView ID="grd_List" runat="server" AutoGenerateColumns="False" onrowdatabound="grd_List_RowDataBound">
<Columns>
<asp:BoundField DataField="Status" HeaderText="Status" ReadOnly="true">
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
</asp:BoundField>
<asp:BoundField DataField="Product" HeaderText="Product" ReadOnly="true">
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
</asp:BoundField>
</Columns>
</asp:GridView>

Grid View RewDataBound Event:

protected void grd_DenominationList_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DataRowView drv = (DataRowView)e.Row.DataItem;
if (drv["Status"].ToString() == "Close")
{
e.Row.BackColor = System.Drawing.Color.Salmon;
}
else if (drv["Status"].ToString() == "Open")
{
e.Row.BackColor = System.Drawing.Color.LightGreen;
}
}

No comments:

Post a Comment