Gridview rowdatabound event firing twice


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

Code for the gridview:

ID="gvHistory" runat="server" AutoGenerateColumns="False"
BorderStyle="Solid" BorderWidth="1pt"
DataKeyNames="ChangeRequestID,ARStatus,ChangeType" DataSourceID="dsHistory"
<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
<asp:TemplateField HeaderText="Authoriser
<asp:TemplateField HeaderText="Change(s)
<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"
<RowStyle VerticalAlign="Top" />
<HeaderStyle BackColor="#D9D5D2" ForeColor="#D7451A"
HorizontalAlign="Left" VerticalAlign="Top" />

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"
e.Row.Cells(6).Text = "No"
End If
If e.Row.Cells(17).Text = "1" Then
e.Row.Cells(5).Text = "Yes"
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


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Latest member

Latest Threads