繼樣品溶液:
C#: ASPX:
<asp:GridView ID="GridView1" runat="server" OnRowDataBound="GridView1_RowDataBound" >
...
</asp:GridView>
代碼隱藏:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
int priority = (int)DataBinder.Eval(e.Row.DataItem, "priority");
switch (priority)
{
case 1:
e.Row.BackColor = Drawing.Color.Green;
break;
case 2:
e.Row.BackColor = Drawing.Color.Red;
break;
default:
e.Row.BackColor = Drawing.Color.Black;
break;
}
}
}
VB.Net代碼隱藏:
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
Select Case e.Row.RowType
Case DataControlRowType.DataRow
Dim priority As Int32 = DirectCast(DataBinder.Eval(e.Row.DataItem, "priority"), Int32)
Select Case priority
Case 1
e.Row.BackColor = Drawing.Color.Green
Case 2
e.Row.BackColor = Drawing.Color.Red
Case Else
e.Row.BackColor = Drawing.Color.Black
End Select
End Select
End Sub
什麼語言,C#或vb.net? – 2010-11-29 15:46:59
對不起,我應該提到這一點。我在VB.Net工作。 – ks78 2010-11-29 15:48:47