Search This Blog

Thursday, March 24, 2011

Highlight the gridview last updated row


Hi most of the time we need to highlight the gridview last update row, because after updating we rebinding the data to the gridview. So it will show the first page only. By the time we need to high light the gridview row, with its page index also.

But we need datakeynames for the gridview, here I used the customer id as the datakeyname. The data key name also must be a numeric field then only its easily to handle.

The css style format for the updated row is as follows
<style type="text/css">
.UpdateRecordCss td
{
border-bottom:solid 1px green;
border-top:solid 1px green;
font-weight:bold;
}
</style>

add the above css in your aspx code and do the following things in the code behind.

protected void Page_Load(object sender, EventArgs e)
{
if (!(Page.IsPostBack))
{
BindGrid();
if(HttpContext.Current.Request["myGVPageId"] != null)
{
gvSample.PageIndex = Convert.ToInt32(HttpContext.Current.Request["myGVPageId"]);
}
}
}

protected void gvSample_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
int id = Convert.ToInt32(gvSample.DataKeys[e.Row.RowIndex].Value.ToString());
if (id == Convert.ToInt32(Session["pkid"]))
e.Row.CssClass = "UpdateRecordCss";
}
}

protected void gvSample_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
TextBox txtCustCode = (TextBox)gvSample.Rows[e.RowIndex].FindControl("txtECustCode");
Session["pkid"] = txtCustCode.Text.ToString();
}

protected void gvSample_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
gvSample.EditIndex = -1;
TextBox txtCustCode = (TextBox)gvSample.Rows[e.RowIndex].FindControl("txtECustCode");
gvSample.PageIndex = Convert.ToInt32(Session["pgindex"]);
Session["pkid"] = txtCustCode.Text.ToString();
BindGrid();
}

1 comment:

  1. Hi could you please send me the complete code...

    Thanks & Regards
    Naresh

    ReplyDelete

Note: Only a member of this blog may post a comment.