data grid and page refresh- functionality and presentation problems

lounge56

Newcomer
Joined
Feb 5, 2004
Messages
14
Hello! I have an web form with two data grids- one data grid shows active documents and the other, documents that have been deleted. For example, if I delete an active document from the data grid (note: function w. stored procedure does this and is called image button), this document should disappear from the data grid with active documents and appear on the deleted items data grid after the function is invoked (note: I assume that this refreshes web form). I am encountering the following problems:

1. When I delete the document, it still appears in the active documents data grid, even though the triggered stored procedure has changed the database record so that it appears in the deleted documents data grid.

2. If I refresh the page after this, the previously deleted document correctly appears in the deleted documents data grid. The thing is the next record containing the status of the next active document in data grid is changed to deleted status. If I refresh page after this, the process is repeated again an again.

Any help would begreatly appreciated.

The following in my source code:


******************* Begin Behind Sample Code **************


'notice that I render data grids here
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim objSurveyDB As New SurveyDB()
Dim ds As DataSet
Dim dr As SqlDataReader
Dim inUserName As String
Dim inUserCode As Integer
Dim inCodArea As Integer
Dim inCodCargo As Integer
Dim inProfileCode As Integer
Dim arrOptionName(6) As String
Dim x As Integer
Dim intGenCounter As Integer
Dim ite As DataGridItem
Dim hyplink As HyperLink
Dim imgbutton As ImageButton


'this renders data grid with active documents
ds = ConvertDataReaderToDataSet(objSurveyDB.GetSurveys(2, inUserCode, inCodCargo, inCodArea, inProfileCode))

griGenSurvey.DataSource() = ds

griGenSurvey.DataBind()

For Each ite In griGenSurvey.Items
For x = 0 To intGenCounter
If arrOptionName(x) = "Edit" Then
hyplink = CType(ite.FindControl("hypSurvEdit"), HyperLink)
'hyplink.NavigateUrl = "~/EDefault.aspx?tid=Edit"
hyplink.Visible = True
Exit For
End If
Next

'image button that invokes delete subroutine (imgbutSurvDelete_Command)
For x = 0 To intGenCounter
If arrOptionName(x) = "Delete" Then
imgbutton = CType(ite.FindControl("imgbutSurvDelete"), ImageButton)
imgbutton.Visible = True
Exit For
End If
Next

For x = 0 To intGenCounter
If arrOptionName(x) = "View" Then
hyplink = CType(ite.FindControl("hypSurvView"), HyperLink)
'hyplink.NavigateUrl = "~/EDefault.aspx?tid=View"
hyplink.Visible = True
Exit For
End If
Next
Next


ds = Nothing

'this renders data grid with deleted documents
ds = ConvertDataReaderToDataSet(objSurveyDB.GetSurveys(3, inUserCode, inCodCargo, inCodArea, inProfileCode))

griDelSurvey.DataSource() = ds

griDelSurvey.DataBind()

ds = Nothing

End Sub

'delete survey sub
Sub imgbutSurvDelete_Command(ByVal sender As Object, ByVal e As CommandEventArgs)
Dim objSurveyDB As New SurveyDB()
Dim Survey As New Survey()
Dim dr As SqlDataReader
Dim inSurveyID As Integer

inSurveyID = e.CommandArgument
If (e.CommandName = "DeleteEvent") Then
dr = objSurveyDB.GenSurveyFunctionality(1, inSurveyID, Now())
End If

End Sub

**************** End Behind sample code *******************

**************** Begin .ascx sample code********************


<%@ Register TagPrefix="surveys" Namespace="Esperantus.WebControls" Assembly="Esperantus" %>
<%@ Control Language="vb" AutoEventWireup="false" Inherits="Xepient.OpenPoint.Survey" CodeBehind="Survey.ascx.vb" Explicit="True" %>
<!-- active documents data grid -->
<asp:datagrid id="griGenSurvey" BorderWidth="0" HeaderStyle-HorizontalAlign="Center" ItemStyle-VerticalAlign="Top" AlternatingItemStyle-BackColor="#cccccc" AutoGenerateColumns="False" runat="server" cellspacing="0" cellpadding="2" Width="900px" HeaderStyle-VerticalAlign="Top">
<Columns>
<asp:BoundColumn DataField="SurveyID" HeaderText="#" HeaderStyle-CssClass="000000Text12Bold" ItemStyle-CssClass="000000Text11Bold"></asp:BoundColumn>
<asp:BoundColumn DataField="SurveyName" HeaderText="Name" HeaderStyle-CssClass="000000Text12Bold" ItemStyle-CssClass="000000Text11Normal"></asp:BoundColumn>
<asp:BoundColumn DataField="SurveyTitle" HeaderText="Title" HeaderStyle-CssClass="000000Text12Bold" ItemStyle-CssClass="000000Text11Normal"></asp:BoundColumn>
<asp:BoundColumn DataField="SurveyDesc" HeaderText="Description" ItemStyle-Width="325" HeaderStyle-CssClass="000000Text12Bold" ItemStyle-CssClass="000000Text11Normal"></asp:BoundColumn>
<asp:BoundColumn DataField="SurveyCreateDate" HeaderText="Date Created" ItemStyle-HorizontalAlign="center" ItemStyle-Width="100" HeaderStyle-CssClass="000000Text12Bold" ItemStyle-CssClass="000000Text11Normal"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="Controls" ItemStyle-Width="85" HeaderStyle-CssClass="000000Text12Bold" ItemStyle-CssClass="000000Text11Normal">
<ItemTemplate>
<asp:hyperlink id="hypSurvEdit" ImageUrl="../../images/icon_pencil.gif" runat="server" NavigateUrl='<%# EditURL("SurveyID",DataBinder.Eval(Container.DataItem,"SurveyID")) %>' Visible="False">
</asp:hyperlink>
<asp:hyperlink id="hypSurvPublish" ImageUrl="../../images/icon_publish.jpg" runat="server" NavigateUrl='<%# EditURL("SurveyID",DataBinder.Eval(Container.DataItem,"SurveyID")) %>' Visible="False">
</asp:hyperlink>
<asp:hyperlink id="hypSurvReports" ImageUrl="../../images/icon_reports.jpg" runat="server" NavigateUrl='<%# EditURL("SurveyID",DataBinder.Eval(Container.DataItem,"SurveyID")) %>' Visible="False">
</asp:hyperlink>
<asp:hyperlink id="hypSurvCopy" ImageUrl="../../images/icon_copy.jpg" runat="server" NavigateUrl='<%# EditURL("SurveyID",DataBinder.Eval(Container.DataItem,"SurveyID")) %>' Visible="False">
</asp:hyperlink>
<asp:ImageButton id="imgbutSurvDelete" ImageUrl="../../images/icon_trashcan.gif" runat="server" CommandName="DeleteEvent" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "SurveyID") %>' OnCommand="imgbutSurvDelete_Command" Visible="False">
</asp:ImageButton>
<asp:hyperlink id="hypSurvView" ImageUrl="../../images/a_BulkEmailManager_s.gif" runat="server" NavigateUrl='<%# EditURL("SurveyID",DataBinder.Eval(Container.DataItem,"SurveyID")) %>' Visible="False">
</asp:hyperlink>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>

<!-- deleleted documents data grid -->
<asp:datagrid id="griDelSurvey" BorderWidth="0" Width="900px" cellpadding="2" cellspacing="0" runat="server" AutoGenerateColumns="False" AlternatingItemStyle-BackColor="#cccccc" ItemStyle-VerticalAlign="Top" HeaderStyle-HorizontalAlign="Center" HeaderStyle-VerticalAlign="Top">
<Columns>
<asp:BoundColumn DataField="SurveyID" HeaderText="#" HeaderStyle-CssClass="000000Text12Bold" ItemStyle-CssClass="000000Text11Bold"></asp:BoundColumn>
<asp:BoundColumn DataField="SurveyName" HeaderText="Name" HeaderStyle-CssClass="000000Text12Bold" ItemStyle-CssClass="000000Text11Normal"></asp:BoundColumn>
<asp:BoundColumn DataField="SurveyTitle" HeaderText="Title" HeaderStyle-CssClass="000000Text12Bold" ItemStyle-CssClass="000000Text11Normal"></asp:BoundColumn>
<asp:BoundColumn DataField="SurveyDesc" HeaderText="Description" HeaderStyle-CssClass="000000Text12Bold" ItemStyle-CssClass="000000Text11Normal"></asp:BoundColumn>
<asp:BoundColumn DataField="SurveyCreateDate" HeaderText="Date Created" ItemStyle-Width="100" ItemStyle-HorizontalAlign="center" HeaderStyle-CssClass="000000Text12Bold" ItemStyle-CssClass="000000Text11Normal"></asp:BoundColumn>
<asp:BoundColumn DataField="SurveyDeleteDate" HeaderText="Date Deleted" ItemStyle-Width="100" ItemStyle-HorizontalAlign="center" HeaderStyle-CssClass="000000Text12Bold" ItemStyle-CssClass="000000Text11Normal"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="Undelete" ItemStyle-HorizontalAlign="center" HeaderStyle-CssClass="000000Text12Bold" ItemStyle-CssClass="000000Text11Normal">
<ItemTemplate>
<asp:CheckBox Runat="server"></asp:CheckBox>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>

**************** End .ascx file **************************



Thank you!
 
The entire dataload should be moved into it's own routine, then in the page laod event call this dataload sub only if it's not a postback.ie

if not IsPostBack then
LoadMyData()
end if

You should also call LoadMyData() when changes are made to the database.
 
Thank you for responding! I did exactly what you suggested. This prevents any Sub I call from functionality buttons (such as a Sub to delete record) from affecting the next record when the page reloads.

The problem is that the data grids are not updated with changes. For example, in reference to the posted code, the grid displaying the active documents (griGenSurvey) should not display the record I just deleted. This record should be displayed in rhe grid displaying the deleted documents (griDelSurvey). My stored procedures do not physically delete records- they just set off a flag that indicates the status of record.

How could I call LoadMyData() in such a way that it prevents functionality from being reused as just explained, but at the same time refreshes data in both data grids?

Thank you!
 
Back
Top