Gaiala
asked on
get last GridView row
Hello,
to insert new data records into a GridView I use the Footertemplate. Each GridView row has an id, text, etc from a xmlfile tag. The problem is that I have to get the Id from the last GridView row so I have an insertion point in the xml file.
so in the button event:
- I nee to get the count of the GridView
- get the content of the first cell of the last row (count of the GridView)
thank you in advice
to insert new data records into a GridView I use the Footertemplate. Each GridView row has an id, text, etc from a xmlfile tag. The problem is that I have to get the Id from the last GridView row so I have an insertion point in the xml file.
so in the button event:
- I nee to get the count of the GridView
- get the content of the first cell of the last row (count of the GridView)
thank you in advice
get the count of the GridView - GridView1.Rows.Count
get the content of the first cell of the last row (count of the GridView) --
GridView1.Rows(GridView1.R ows.Count - 1).Cells(0).Text
GridView1.Rows(GridView1.R
ASKER
ok I have tried to test your example. The code is set in the button event of a footer button.
But I get an exception :(
Unable to cast object of type 'System.Web.UI.WebControls .GridViewR ow' to type 'System.Web.UI.WebControls .GridView' .
But I get an exception :(
Unable to cast object of type 'System.Web.UI.WebControls
Public Sub btnFo_Click(ByVal sender As Object, ByVal e As CommandEventArgs)
Try
Dim ddl1 As Button = CType(sender, Button)
Dim row As GridViewRow = CType(ddl1.NamingContainer, GridViewRow)
' here I get an exception
Dim gv As GridView = CType(ddl1.NamingContainer, GridView)
Dim strText As String = gv.Rows(gv.Rows.Count - 1).Cells(0).Text()
Dim txtInfo As TextBox
Dim txtInput As TextBox
Dim strInfo As String
Dim strInput As String
txtInfo = CType(row.FindControl("foTxt01"), TextBox)
txtInput = CType(row.FindControl("foTxt02"), TextBox)
strInfo = txtInfo.Text
strInput = txtInput.Text
Catch ex As Exception
End Try
End Sub
End Class
Public Class FooterTemplateText
Implements ITemplate
Public Sub InstantiateIn(ByVal container As System.Web.UI.Control) Implements System.Web.UI.ITemplate.InstantiateIn
Try
Dim txtFo As New TextBox
txtFo.ID = "foTxt01"
txtFo.TextMode = TextBoxMode.MultiLine
txtFo.Visible = True
container.Controls.Add(txtFo)
Catch ex As Exception
End Try
End Sub
End Class
Dim gv As GridView = CType(ddl1.NamingContainer , GridView)
why you used this ? did you want to create new grid view ?
gv.Rows(gv.Rows.Count - 1).Cells(0).Text()
This will give you result if gridview is already present & binded
why you used this ? did you want to create new grid view ?
gv.Rows(gv.Rows.Count - 1).Cells(0).Text()
This will give you result if gridview is already present & binded
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.