J
Julia B
All, apologies, this is a 2nd posting, but I posted a few weeks ago and
didn't get any responses, and I really need some help.
I've got a content page within a master page with a gridview on it. It's
populated with an objectdatasource. The content page's autoeventwireup
property is set to false but the gridview rowdatabound event still fires
twice, which is causing real problems.
This is the order of what happens:
1 - the content page loads first
2 - the gridview loads firing the rowdatabound event the first time
3 - then the master page loads
4 - then the gridview reloads firing the rowdatabound event the second time
(the content page's load event doesn't fire twice)
Does this make sense? Has anyone any suggestions on how to stop this
happening?
Code for the gridview:
<asp:GridView
ID="gvHistory" runat="server" AutoGenerateColumns="False"
BorderColor="#D9D5D2"
BorderStyle="Solid" BorderWidth="1pt"
DataKeyNames="ChangeRequestID,ARStatus,ChangeType" DataSourceID="dsHistory"
Font-Names="Tahoma">
<Columns>
<asp:BoundField DataField="ChangeType" HeaderText="Type" />
<asp:BoundField DataField="ARStatus" HeaderText="Status" />
<asp:BoundField DataField="RequestDate"
HeaderText="Submitted" DataFormatString="{0:d}" />
<asp:BoundField DataField="RequestApprovedDate"
HeaderText="Approved" DataFormatString="{0:d}" />
<asp:BoundField DataField="ChangeDueBy" HeaderText="Due"
DataFormatString="{0:d}" />
<asp:TemplateField HeaderText="Manager
Changed"></asp:TemplateField>
<asp:TemplateField HeaderText="Authoriser
Changed"></asp:TemplateField>
<asp:TemplateField HeaderText="Change(s)
Required"></asp:TemplateField>
<asp:CommandField SelectText="Full Request"
ShowSelectButton="True" />
<asp:BoundField DataField="AddNewAccounts"
HeaderText="_AddNewAccounts" />
<asp:BoundField DataField="DeleteAccounts"
HeaderText="_DeleteAccounts" />
<asp:BoundField DataField="NewForename"
HeaderText="_NewForename" />
<asp:BoundField DataField="NewSurname"
HeaderText="_NewSurname" />
<asp:BoundField DataField="NewDept" HeaderText="_NewDept" />
<asp:BoundField DataField="NewJobTitle"
HeaderText="_NewJobTitle" />
<asp:BoundField DataField="NewContractEndDate"
HeaderText="NewContractEndDate" />
<asp:BoundField DataField="NewAuthoriser"
HeaderText="_NewAuthoriser" />
<asp:BoundField DataField="NewManager"
HeaderText="_NewManager" />
<asp:BoundField DataField="ChangeRequestID" HeaderText="_ID"
/>
</Columns>
<RowStyle VerticalAlign="Top" />
<HeaderStyle BackColor="#D9D5D2" ForeColor="#D7451A"
HorizontalAlign="Left" VerticalAlign="Top" />
</asp:GridView>
And the rowdatabound event:
Private Sub gvHistory_RowDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvHistory.RowDataBound
'fill the 3 extra columns with data depending on the latter columns
'which are going to be hidden
If Not Me.IsPostBack Then
If e.Row.RowType = DataControlRowType.DataRow Then
If e.Row.Cells(16).Text = "1" Then
e.Row.Cells(6).Text = "Yes"
Else
e.Row.Cells(6).Text = "No"
End If
If e.Row.Cells(17).Text = "1" Then
e.Row.Cells(5).Text = "Yes"
Else
e.Row.Cells(5).Text = "No"
End If
Dim changeString As String = "Details:"
If e.Row.Cells(9).Text <> " " Then
changeString += " {add new account(s)}"
End If
If e.Row.Cells(10).Text <> " " Then
changeString += " {delete account(s)}"
End If
If e.Row.Cells(11).Text <> " " Then
changeString += " {changed forename}"
End If
If e.Row.Cells(12).Text <> " " Then
changeString += " {changed surname}"
End If
If e.Row.Cells(13).Text <> " " Then
changeString += " {changed dept}"
End If
If e.Row.Cells(14).Text <> " " Then
changeString += " {changed job title}"
End If
If e.Row.Cells(15).Text <> " " Then
changeString += " {new contract end date}"
End If
If changeString <> "Details:" Then
e.Row.Cells(7).Text = changeString
End If
End If
End If
End Sub
Julia
didn't get any responses, and I really need some help.
I've got a content page within a master page with a gridview on it. It's
populated with an objectdatasource. The content page's autoeventwireup
property is set to false but the gridview rowdatabound event still fires
twice, which is causing real problems.
This is the order of what happens:
1 - the content page loads first
2 - the gridview loads firing the rowdatabound event the first time
3 - then the master page loads
4 - then the gridview reloads firing the rowdatabound event the second time
(the content page's load event doesn't fire twice)
Does this make sense? Has anyone any suggestions on how to stop this
happening?
Code for the gridview:
<asp:GridView
ID="gvHistory" runat="server" AutoGenerateColumns="False"
BorderColor="#D9D5D2"
BorderStyle="Solid" BorderWidth="1pt"
DataKeyNames="ChangeRequestID,ARStatus,ChangeType" DataSourceID="dsHistory"
Font-Names="Tahoma">
<Columns>
<asp:BoundField DataField="ChangeType" HeaderText="Type" />
<asp:BoundField DataField="ARStatus" HeaderText="Status" />
<asp:BoundField DataField="RequestDate"
HeaderText="Submitted" DataFormatString="{0:d}" />
<asp:BoundField DataField="RequestApprovedDate"
HeaderText="Approved" DataFormatString="{0:d}" />
<asp:BoundField DataField="ChangeDueBy" HeaderText="Due"
DataFormatString="{0:d}" />
<asp:TemplateField HeaderText="Manager
Changed"></asp:TemplateField>
<asp:TemplateField HeaderText="Authoriser
Changed"></asp:TemplateField>
<asp:TemplateField HeaderText="Change(s)
Required"></asp:TemplateField>
<asp:CommandField SelectText="Full Request"
ShowSelectButton="True" />
<asp:BoundField DataField="AddNewAccounts"
HeaderText="_AddNewAccounts" />
<asp:BoundField DataField="DeleteAccounts"
HeaderText="_DeleteAccounts" />
<asp:BoundField DataField="NewForename"
HeaderText="_NewForename" />
<asp:BoundField DataField="NewSurname"
HeaderText="_NewSurname" />
<asp:BoundField DataField="NewDept" HeaderText="_NewDept" />
<asp:BoundField DataField="NewJobTitle"
HeaderText="_NewJobTitle" />
<asp:BoundField DataField="NewContractEndDate"
HeaderText="NewContractEndDate" />
<asp:BoundField DataField="NewAuthoriser"
HeaderText="_NewAuthoriser" />
<asp:BoundField DataField="NewManager"
HeaderText="_NewManager" />
<asp:BoundField DataField="ChangeRequestID" HeaderText="_ID"
/>
</Columns>
<RowStyle VerticalAlign="Top" />
<HeaderStyle BackColor="#D9D5D2" ForeColor="#D7451A"
HorizontalAlign="Left" VerticalAlign="Top" />
</asp:GridView>
And the rowdatabound event:
Private Sub gvHistory_RowDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvHistory.RowDataBound
'fill the 3 extra columns with data depending on the latter columns
'which are going to be hidden
If Not Me.IsPostBack Then
If e.Row.RowType = DataControlRowType.DataRow Then
If e.Row.Cells(16).Text = "1" Then
e.Row.Cells(6).Text = "Yes"
Else
e.Row.Cells(6).Text = "No"
End If
If e.Row.Cells(17).Text = "1" Then
e.Row.Cells(5).Text = "Yes"
Else
e.Row.Cells(5).Text = "No"
End If
Dim changeString As String = "Details:"
If e.Row.Cells(9).Text <> " " Then
changeString += " {add new account(s)}"
End If
If e.Row.Cells(10).Text <> " " Then
changeString += " {delete account(s)}"
End If
If e.Row.Cells(11).Text <> " " Then
changeString += " {changed forename}"
End If
If e.Row.Cells(12).Text <> " " Then
changeString += " {changed surname}"
End If
If e.Row.Cells(13).Text <> " " Then
changeString += " {changed dept}"
End If
If e.Row.Cells(14).Text <> " " Then
changeString += " {changed job title}"
End If
If e.Row.Cells(15).Text <> " " Then
changeString += " {new contract end date}"
End If
If changeString <> "Details:" Then
e.Row.Cells(7).Text = changeString
End If
End If
End If
End Sub
Julia