Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. how to highlight newly inserted record in a gridview with paging=true?

how to highlight newly inserted record in a gridview with paging=true?

Scheduled Pinned Locked Moved ASP.NET
tutorialquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Pawan Kiran
    wrote on last edited by
    #1

    hi i have a gridview. i am filling gridview through a view, i am inserting a record through a storedprocedure and i want to display the last inserted record as a last record and also i want to highlight the record as well as focus on the newly inserted record. provide code for this one.. Koti

    A M 2 Replies Last reply
    0
    • P Pawan Kiran

      hi i have a gridview. i am filling gridview through a view, i am inserting a record through a storedprocedure and i want to display the last inserted record as a last record and also i want to highlight the record as well as focus on the newly inserted record. provide code for this one.. Koti

      A Offline
      A Offline
      Amol 111
      wrote on last edited by
      #2

      Assuming your first row of gridview is the last inserted record in design mode provide backcolor in SelectedRowStyle or in your CSS. then in ur insert function after Binding gridview write the below line

      gridview1.SelectedIndex = 0;

      1 Reply Last reply
      0
      • P Pawan Kiran

        hi i have a gridview. i am filling gridview through a view, i am inserting a record through a storedprocedure and i want to display the last inserted record as a last record and also i want to highlight the record as well as focus on the newly inserted record. provide code for this one.. Koti

        M Offline
        M Offline
        Member 3878553
        wrote on last edited by
        #3

        The Code In order to run the code below, you must first set up Membership. The simplest way to do this is to simply add to your web.config a very small section enabling RoleManager. This will automatically create the membership database in sqlexpress. You should probably add a couple users just so your gridview is not empty from the start. The code you need to add to an empty asp.net 2.0 web site project is as follows (put it in the <System.Web> section). <roleManager enabled=“true“></roleManager> Once you have done that, you can copy the code below to a new web page and simply run it. Briefly, the way the code works is that when a row is inserted into the database the sqldatasource’s Inserted event is called. In this event, we take a look at the return parameter which comes from the sql: InsertCommand=”INSERT INTO [Names] ([name]) VALUES (@name);SELECT @NewID = Scope_Identity()” NewId is actually a return parameter, so we can get that back in the inserted event. Once we get the value back, we store it in viewstate so that on the upcoming page_prerender, we can check and see which row has that id in it, and then highlight that row. The reason we do it in prerender and not load is because the inserted event is processed after load and it would not work if we put it there. So, here is the code! Good luck. <%@ Page Language=”C#” %> <!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”> <script runat=”server”> // simple table named: Names. Two columns: id int, name varchar(64) protected void ButtonInsert_Click(object sender, EventArgs e) { SqlDataSource1.InsertParameters["name"].DefaultValue = DateTime.Now.ToString(); int numInserted = SqlDataSource1.Insert(); GridView1.DataBind(); } protected void SqlDataSource1_Inserted(object sender, SqlDataSourceStatusEventArgs e) { object newId = e.Command.Parameters["@NewId"].Value; ViewState["NewId"] = Convert.ToInt32(newId); } protected void Page_PreRender(object sender, EventArgs e) { string newIdLast = string.Empty; if (ViewState["NewId"] != null) { int newId = (int)ViewState["NewId"]; newIdLast = newId.ToString(); int rowCnt = 0; foreach (GridViewRow row in GridView1.Rows) {

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups