Add a Blank Row to Gridview?
-
Hello, Does anyone have a code snippet for adding a blank row at the end or top of the gridview on a button click?The button is outside the GV and not in the footer. I did it in datagrid and I guess it was easier.But for gridview it isn't working. I will post my little snippet but it is giving me error: Protected Sub btnadddriver_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnadddriver.Click DriverGV.DataBind() Dim ds As DataSet = DriverGV.DataSource Dim blank As System.Data.DataRow = ds.Tables(0).NewRow() ds.Tables(0).Rows.InsertAt(blank, ds.Tables(0).Rows.Count) DriverGV.EditIndex = ds.Tables(0).Rows.Count - 1 DriverGV.DataBind() End Sub The error I am getting is : Exception Details: System.NullReferenceException: Object reference not set to an instance of an object Line 16: Dim blank As System.Data.DataRow = ds.Tables(0).NewRow() If someone has a working snippet for adding a blank row to the gridview can you kindly help me? I'm on Visual Studio2005,Asp.Net2.0,VB Thanks.All help is much appreciated.
Aartee. ...HE is watching Us All!
-
Hello, Does anyone have a code snippet for adding a blank row at the end or top of the gridview on a button click?The button is outside the GV and not in the footer. I did it in datagrid and I guess it was easier.But for gridview it isn't working. I will post my little snippet but it is giving me error: Protected Sub btnadddriver_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnadddriver.Click DriverGV.DataBind() Dim ds As DataSet = DriverGV.DataSource Dim blank As System.Data.DataRow = ds.Tables(0).NewRow() ds.Tables(0).Rows.InsertAt(blank, ds.Tables(0).Rows.Count) DriverGV.EditIndex = ds.Tables(0).Rows.Count - 1 DriverGV.DataBind() End Sub The error I am getting is : Exception Details: System.NullReferenceException: Object reference not set to an instance of an object Line 16: Dim blank As System.Data.DataRow = ds.Tables(0).NewRow() If someone has a working snippet for adding a blank row to the gridview can you kindly help me? I'm on Visual Studio2005,Asp.Net2.0,VB Thanks.All help is much appreciated.
Aartee. ...HE is watching Us All!
Hi there: This article NewRowGridView might help you... << >>