Pages

Saturday, November 27, 2010

Format Gridview with OnRowCreated function


----------------------------------------------------------------------------------
1

if (e.Row.RowType == DataControlRowType.DataRow)
{
Comments = (String)DataBinder.Eval(e.Row.DataItem, "Comment");
if (Comments.Length > 30)
{
Comments = Comments.Substring(0, 40) +"...";
e.Row.ForeColor = System.Drawing.Color.Crimson;
e.Row.Font.Italic = true;
}
}

---------------------------------------------------------------------------------
2
protected void grdData_RowCreated(object sender, GridViewRowEventArgs e)
{

if ((e.Row.RowType == DataControlRowType.DataRow) && (e.Row.RowState == DataControlRowState.Selected))
{
string strCellvalue = DataBinder.Eval(e.Row.DataItem, "categoryname").ToString();
if (strCellvalue == "Admin")
{
e.Row.BackColor = System.Drawing.Color.LightPink;
}
}
}

#######################################################
3

<asp:GridView runat="server" ID="gridProducts" DataSourceID="productsSource"
AutoGenerateColumns="false" OnRowCreated="gridProducts_RowCreated">
<Columns>
<asp:BoundField DataField="ProductID" HeaderText="ID" />
<asp:BoundField DataField="Name" HeaderText="Name" />
<asp:BoundField DataField="ProductNumber" HeaderText="Number" />
<asp:BoundField DataField="DaysToManufacture" HeaderText="Days To Manufacture" />
</Columns>
</asp:GridView>

protected void gridProducts_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
int daysToManufacture = (int)DataBinder.Eval(e.Row.DataItem, "DaysToManufacture");

if (daysToManufacture == 0)
{
e.Row.BackColor = System.Drawing.Color.LightPink;
e.Row.ForeColor = System.Drawing.Color.Maroon;
}
else if (daysToManufacture == 1)
{
e.Row.BackColor = System.Drawing.Color.LightCyan;
e.Row.ForeColor = System.Drawing.Color.DarkBlue;
}
else
{
e.Row.BackColor = System.Drawing.Color.LightGray;
e.Row.ForeColor = System.Drawing.Color.Red;
}
}
}
####################################################


0 comments:

Post a Comment

 

CodeAddict.com | Copyright 2009 Tüm Haklar? Sakl?d?r | Free Blogger Templates by GoogleBoy Download Free Wordpress Templates. Unblock through unblock myspace proxy, Hillsongs by Guitar Song Chords