-2

Time 列の値が 30 より大きい場合に行の背景色を変更する方法を見つけようとしています。以下は私のコードです。

<asp:GridView ID="gvMyDetails" runat="server" AutoGenerateColumns="False" AllowSorting="true" CellPadding="0"
    Width="730px" BackColor="White" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px"
    Font-Bold="True" ForeColor="Black" OnSelectedIndexChanged="gvMyDetails_SelectedIndexChanged"
    Style="text-align: center">
    <Columns>
        <!-- Other asp:TemplateFields... -->
        <asp:TemplateField HeaderText="Time" HeaderStyle-BackColor="#4b6c9e">
            <ItemTemplate>
                &nbsp; &nbsp;
                <asp:Label ID="lblTime" runat="server" Text='<%# Bind("Time") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
    <FooterStyle BackColor="#CCCCCC" />
    <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
    <SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
    <HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
    <AlternatingRowStyle BackColor="#CCCCCC" />
</asp:GridView>
SqlDataReader myReader4 = null;
SqlCommand myCommand4 = new SqlCommand("SELECT Account_Number, Std_Note_Code, Std_Note_Description, CONVERT(varchar(12), Std_Note_Date_Entered, 101) as datedate, Std_Note_Time_Entered, Time FROM qa_bor, qa_users where (qa_bor.Std_Note_Creator_Name = qa_users.username_bor and qa_users.username_bor = '" + ddlrep.Text + "') and (qa_bor.Std_Note_Date_Entered >= '" + datefrom + "' and qa_bor.Std_Note_Date_Entered <= '" + dateto + "') ORDER BY Std_Note_Date_Entered ASC", myConnection);
myReader4 = myCommand4.ExecuteReader();
if (myReader4.HasRows)
{
    gvMyDetails.DataSource = myReader4;                                
    gvMyDetails.DataBind();
    myReader4.Close();               
}
4

1 に答える 1

1

以下の例:

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) 
{ 
    e.Row.Attributes.Add("style", "cursor:help;"); 
    if (e.Row.RowType == DataControlRowType.DataRow && e.Row.RowState == DataControlRowState.Alternate) 
    {  
        if (e.Row.RowType == DataControlRowType.DataRow) 
        {                 
            e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='orange'"); 
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#E56E94'"); 
            e.Row.BackColor = Color.FromName("#E56E94");                 
        }            
    } 
    else 
    { 
        if (e.Row.RowType == DataControlRowType.DataRow) 
        { 
            e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='orange'"); 
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='gray'"); 
            e.Row.BackColor = Color.FromName("gray");                 
        } 
于 2012-08-15T17:11:09.737 に答える