在GridView中更改行颜色

在GridView中更改行颜色

本文介绍了在GridView中更改行颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我在gridview中删除了按钮控件,当我按下该按钮时,它会更新该行的状态以删除并将其背景颜色更改为红色。我在RowCommand事件中使用了以下代码

Hi All,
I have delete button control in gridview when i press that button it will update the status of that row to deleted and change its background color to red. i have used following code in RowCommand event

protected void GridView_RowCommand(object sender, GridViewCommandEventArgs e)
       {
           if (e.CommandName == "Delete")
               {
                  dgvJV.RowStyle.BackColor = Color.Red;
               }
       }





...但它会将整个gridview更改为红色..所以我想我需要得到行索引..我怎么能在RowCommand事件中做到这一点?



感谢提前



... but it changes the whole gridview to red .. so I guess I need to get row index.. How can I do that in RowCommand Event?

thanks in Advance

推荐答案

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {

            if (e.CommandName == "Delete")
            {


                GridViewRow selectedRow = (GridViewRow)((ImageButton)e.CommandSource).NamingContainer;
                int RowIndexx = Convert.ToInt32(selectedRow.RowIndex);

                GridView1.Rows[RowIndexx].BackColor = System.Drawing.Color.Blue;

           }
}


CommandArgument='<%# Container.DataItemIndex%>' 





它会将您的行索引分配给命令参数。

Access行命令事件中的这一行索引&试试这样的事情..



it will assign your row index to command argument.
Access this row index in row command event & try something like this..

protected void GridView_RowCommand(object sender, GridViewCommandEventArgs e)
        {

            if (e.CommandName == "Delete")
            {
                   int index = e.CommandArgument;
                   GridViewRow deletedRow= MyGridView.Rows[index];
                   deletedRow.BackColor= Color.Red;

            }
        }


这篇关于在GridView中更改行颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 18:16