Highlight Last entered Gridview Row(vb)

What's the best way to highlight the last grid view row that has just been inserted into a DB.
EdAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Lokesh B RDeveloperCommented:
Hi,

Sample code here to highlight the last added row.

Protected Sub Page_Load(sender As Object, e As EventArgs)
	If Not IsPostBack Then
		Dim dt As New DataTable()
		dt.Columns.Add("Name", GetType(String))
		dt.Rows.Add("Scott")

		GridView1.DataSource = dt
		GridView1.DataBind()

		ViewState("data") = dt
	End If
End Sub

Protected Sub GridView1_RowDataBound(sender As Object, e As GridViewRowEventArgs)
	If e.Row.RowType = DataControlRowType.DataRow Then
		If e.Row.Cells(0).Text = TextBox1.Text Then
			e.Row.BackColor = System.Drawing.Color.Green
		End If
	End If
End Sub

Protected Sub btnAdd_Click(sender As Object, e As EventArgs)
	Dim dt As DataTable

	If ViewState("data") Is Nothing Then
		dt = New DataTable()
		dt.Columns.Add("Name", GetType(String))
	Else
		dt = DirectCast(ViewState("data"), DataTable)
	End If

	dt.Rows.Add(TextBox1.Text)
	GridView1.DataSource = dt
	GridView1.DataBind()
End Sub

Open in new window


ASPX

<asp:GridView ID="GridView1" runat="server" OnRowDataBound="GridView1_RowDataBound"></asp:GridView>
       
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1" ErrorMessage="RequiredFieldValidator"></asp:RequiredFieldValidator>
        <br />
        <asp:Button ID="btnAdd" runat="server" OnClick="btnAdd_Click" Text="Add Row" />

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
EdAuthor Commented:
perfect
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.