高亮显示网格视图中的最后一条记录 [英] hightlight last record in grid view

查看:72
本文介绍了高亮显示网格视图中的最后一条记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请告诉我如何突出显示gridview中最后插入的记录?网格视图中的数据显示来自存储过程与sql server连接。



我没有得到确切的代码。



请帮帮我。

Please tell me how to highlight the last inserted record in the gridview? Data in gird view is showing from store procedure with sql server connectivity.

I'm not getting the exact code for this.

please help me out.

推荐答案

在Page_Load事件处理程序中使用以下代码

use the following code inside the Page_Load event handler
int lastRowIndex = 0;
if (!IsPostBack)
{
    dgTest.DataSource = GetDataTable(); //the GetDataTable function returns a DataTable
    dgTest.DataBind();
}
foreach (GridViewRow grv in dgTest.Rows)
{
    if (grv.RowType == DataControlRowType.DataRow)
    {
        if (grv.RowIndex > lastRowIndex)
        {
            //getting the last data row index
            lastRowIndex = grv.RowIndex;
        }
    }
}
//dgTest.Rows[lastRowIndex].CssClass = "lastRowClass";
dgTest.Rows[lastRowIndex].BackColor = System.Drawing.Color.Red;



lastRowClass是可用于突出显示最后一行的CSS类的名称。检查此代码以查看最后一行是否显示红色。


The lastRowClass is the name of the CSS class that can be used to highlight the last row. Check this code to see whether the last row gets the red color or not.


请检查我的代码...

并且它仍然无效...当我运行此代码然后在第一页的最后一行它显示红色但当我填写所有文本框并保存比它不工作。

please check my code...
and its still not working...when i m running this code then on the first page last row its showing red but when i fill all text boxes and save than its not working .
public partial class Create_New_Customer : System.Web.UI.Page
    {
  int lastRowIndex = 0;
 protected void Page_Load(object sender, EventArgs e)
        {
if (!IsPostBack)
            {
                // con = new SqlConnection("Data Source=NSEZ-DD4-028;Initial Catalog=Insurance;Integrated Security= SSPI");
                con = new SqlConnection(connStr);

                cmd = new SqlCommand("Create_Customer_All", con);
                cmd.CommandType = CommandType.StoredProcedure;
                con.Open();
                cmd.Connection = con;
                SqlDataAdapter adapter = new SqlDataAdapter(cmd);
                adapter.Fill(ds);
                gridviewCustomer.DataSource = ds;
                gridviewCustomer.DataBind();
                con.Close();
//            }

            foreach (GridViewRow grv in gridviewCustomer.Rows)
            {
                if (grv.RowType == DataControlRowType.DataRow)
                {
                    if (grv.RowIndex > lastRowIndex)
                    {
                        lastRowIndex = grv.RowIndex;
                    }
                }
            }
       //     gridviewCustomer.Rows[lastRowIndex].CssClass = "lastRowClass";
            gridviewCustomer.Rows[lastRowIndex].BackColor = System.Drawing.Color.Red;
            //    con.Close();
        }


我得到了解决方案

感谢您帮助我:)


公共舱


int lastRowIndex = 0;





保存按钮

i got the solution
thanks for helping me out :)

on public class
int lastRowIndex = 0;


on save button
lastRowIndex = gridviewNewClaimType.Rows.Count - 1;
           gridviewNewClaimType.Rows[lastRowIndex].BackColor = System.Drawing.Color.LightBlue;
       }


这篇关于高亮显示网格视图中的最后一条记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆