单击按钮后单元格颜色发生变化

问题描述 投票:0回答:1

我正在使用asp.net中的gridview,当我单击按钮字段时,在应用的gridview按钮字段中,行的颜色已更改,但是当单击另一个按钮字段时,前一行的颜色将更改为正常颜色。我希望所有的行颜色在单击按钮字段时都发生更改。我想要output,但在单击下一个按钮字段时得到outputs

  front-end code
   <asp:GridView ID="GridView1" runat="server" AllowSorting="True"  OnSorting="GridView1_Sorting" AutoGenerateColumns="False" OnRowCommand="GridView1_RowCommand" OnRowDataBound="GridView1_RowDataBound"    >
        <Columns>

            <asp:BoundField DataField="name" HeaderText="Name" SortExpression="name" />
            <asp:BoundField DataField="suser" HeaderText="GR no" SortExpression="suser" />
            <asp:BoundField DataField="classname" HeaderText="Class Name" SortExpression="classname" />
            <asp:BoundField DataField="rollno" HeaderText="Roll No" SortExpression="rollno" />
            <asp:ButtonField ButtonType="Button" HeaderText="Attendance" Text="Present" CommandName="attendance"  />
            <asp:ButtonField ButtonType="Button" CommandName="apsent" HeaderText="Attendance" Text="Apsent" />
        </Columns>
    </asp:GridView>

   back-end code
    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
    if (e.CommandName == "attendance")
    {                   
        int crow = Convert.ToInt32(e.CommandArgument.ToString());
        GridView1.Rows[crow].Cells[3].BackColor = System.Drawing.Color.GreenYellow;
    }

}

image现在,如果我单击rollno(04)buttonfield,则颜色变为绿色。这样,如果我单击每个按钮字段,那么相应的rollno的颜色就会发生变化

c# sql .net
1个回答
0
投票

您可以输入以下代码

Row.BackColor = Color.FromName("green");
© www.soinside.com 2019 - 2024. All rights reserved.