I am trying to store a datagrid constantly in the code behind of my page, when i click delete i need to remove a row from it and then rebind to the gridview but i keep losing the state of the datagrid and cant fix it.
Private _dtTop20 As DataTable
Public Property dtTop20() As DataTable
Get
Return _dtTop20
End Get
Set(ByVal value As DataTable)
_dtTop20 = value
End Set
End Property
Private Sub BrSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BrSearch.Click
Dim obj As New SalesDW_BL_Top20
_dtTop20 = obj.Sales_listTop20_GetCustomer(ApplicationID, _User.LogonName, _
DCSalesManager.SelectedValue, DrpYears.SelectedValue, DrpSector.SelectedValue)
End Sub
Private Sub gvEdit_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles gvEdit.RowDeleting
Dim value As New DataTable
value = dtTop20
value.Rows.RemoveAt(e.RowIndex)
_dtTop20 = value
End Sub
Private Sub gvEdit_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles gvEdit.RowDeleting
Dim value As New DataTable
value = dtTop20
value.Rows.RemoveAt(e.RowIndex)
_dtTop20 = value
gvEdit.DataSource = _dtTop20
gvEdit.DataBind()
End Sub
Case you not have an instance of DataTable you can storage it in Session, Cache or ViewState.
I hope this help
Kindly mark this post as "Answer", if it helped you.
connersz
Member
153 Points
175 Posts
Problems setting and getting data from public property datagrid
May 01, 2012 12:55 PM|LINK
Hi,
I am trying to store a datagrid constantly in the code behind of my page, when i click delete i need to remove a row from it and then rebind to the gridview but i keep losing the state of the datagrid and cant fix it.
Private _dtTop20 As DataTable Public Property dtTop20() As DataTable Get Return _dtTop20 End Get Set(ByVal value As DataTable) _dtTop20 = value End Set End PropertyPrivate Sub BrSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BrSearch.Click Dim obj As New SalesDW_BL_Top20 _dtTop20 = obj.Sales_listTop20_GetCustomer(ApplicationID, _User.LogonName, _ DCSalesManager.SelectedValue, DrpYears.SelectedValue, DrpSector.SelectedValue) End SubPrivate Sub gvEdit_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles gvEdit.RowDeleting Dim value As New DataTable value = dtTop20 value.Rows.RemoveAt(e.RowIndex) _dtTop20 = value End Subpierrefrc
Participant
947 Points
201 Posts
Re: Problems setting and getting data from public property datagrid
May 01, 2012 01:06 PM|LINK
Hi
If you have an instance of DataTable you can use:
Private Sub gvEdit_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles gvEdit.RowDeleting Dim value As New DataTable value = dtTop20 value.Rows.RemoveAt(e.RowIndex) _dtTop20 = value gvEdit.DataSource = _dtTop20 gvEdit.DataBind() End SubI hope this help