Yes, but a lot depends on how much time you have and how much you are willing
to commit to get this done.
I created a project from scratch that fundamentally perform the task you
suggested the way I did it was to place a gridview and button on a page then
perform a little magic as show below
Essentially create a datatable with the rows as show then add a new row to
the datatable and set editindex to the row. Of course you need to know the
row number or perform some magic so your new row show on top then you can set
editindex = 0.
For my example I added a command field through the wizard but even this can
be done programmatically. The add button while external for the example
could easily made in to a template field to make it part of the grid.
The more you customize the harder it gets especially if you doing it for the
first time. If you doing this for something you have to deliver soon then I
suggest exploring the third party community for a solution. But if you have
time or just exploring have at it is fun.
Regards
ps
The example is not complete by any means it just shows the approach you
could take and is not a complete solution.
[The Page]
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb"
Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="
http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" CellPadding="4"
ForeColor="#333333"
GridLines="None">
<FooterStyle BackColor="#507CD1" Font-Bold="True"
ForeColor="White" />
<RowStyle BackColor="#EFF3FB" />
<Columns>
<asp:CommandField ShowEditButton="True" />
</Columns>
<PagerStyle BackColor="#2461BF" ForeColor="White"
HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True"
ForeColor="#333333" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True"
ForeColor="White" />
<EditRowStyle BackColor="#2461BF" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
</div>
<asp:Button ID="Button1" runat="server" Text="Add" />
</form>
</body>
</html>
[code behind]
Imports System.Data
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
BindGridView()
End Sub
Private Sub BindGridView()
Dim da As New DataLayer.SqlDataAccess
Dim sql As String = "Select * from categories"
Dim dt As DataTable = da.GetDataTable(sql)
GridView1.DataSource = dt
GridView1.DataBind()
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim dt As datatable = CType(GridView1.DataSource, datatable)
Dim rw As DataRow = dt.NewRow
rw.Item(0) = "0000"
dt.Rows.Add(rw)
GridView1.EditIndex = 8
GridView1.DataBind()
End Sub
Protected Sub GridView1_RowCancelingEdit(ByVal sender As Object, ByVal e
As System.Web.UI.WebControls.GridViewCancelEditEventArgs) Handles
GridView1.RowCancelingEdit
End Sub
Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles
GridView1.RowUpdating
End Sub
End Class