【问题标题】:Cell color change after click on butonfiled单击按钮字段后单元格颜色更改
【发布时间】:2019-12-31 11:16:35
【问题描述】:

我在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) 按钮字段,则颜色变为绿色。 像这样,如果我点击每个按钮字段,那么相应的 rollno 的颜色就会改变

【问题讨论】:

  • 不清楚,您能否发布一个示例图像,您希望输出如何

标签: c# sql .net


【解决方案1】:

你可以如下代码

Row.BackColor = Color.FromName("green");

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-03-18
    • 2018-08-01
    • 2016-11-10
    • 1970-01-01
    • 2012-12-06
    • 2021-02-22
    • 1970-01-01
    • 2014-08-26
    相关资源
    最近更新 更多