Question Nested Gridview displaying duplicate data

ddrhoward

New member
Joined
Jul 19, 2013
Messages
1
Programming Experience
5-10
I have a nested gridview that is displaying duplicate data for some reason. When I run the stored procedure, the data is correct. Could it have something to do with me binding the gridview in the rowdatabound event.

Here's my code behind

ProtectedSub grdTotal_RowDataBound(ByVal sender AsObject, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles grdTotal.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
' pull gridview data
Dim DBConn = New SqlConnection(Application("DBConn"))
Dim cmdCounty As SqlCommand = New SqlCommand("spPICAInsertTotals", DBConn)
cmdCounty.CommandType = CommandType.StoredProcedure
Dim gv As GridView = TryCast(e.Row.FindControl("grdChild"), GridView)
strUser = Session(
"User")
Dim UserID AsNew SqlParameter("@UserID", SqlDbType.Int)
UserID.Value = strUser
cmdCounty.Parameters.Add(UserID)
DBConn.Open()
gv.DataSource = cmdCounty.ExecuteReader
gv.DataBind()
gv.Visible =
True
DBConn.Close()
btnExport.Visible =
True
lblmsg.Visible = False
lblInstructions.Visible = False
ForEach row As GridViewRow In gv.Rows
intRowCount += 1
Next
EndIf
EndSub




This is the design code..

<asp:GridView ID="grdTotal" ShowFooter="true" AutoGenerateColumns="False"
runat="server" OnRowDataBound="grdTotal_RowDataBound" CellPadding="4"
ForeColor="#333333" GridLines="None" style="text-align: left"
ShowHeader="False">

<Columns>

<asp:TemplateField>
<ItemTemplate>
<br />
<asp:Label ID="Label1" runat="server" style="text-align: left" Text="Year:" />  <asp:Label ID="lblTitle" runat="server" style="text-align: left" Text='<%# Eval("Year") %>' />
<br />
<asp:GridView ID="grdChild" runat="server" AutoGenerateColumns="False" CellPadding="0" CellSpacing="4" ForeColor="#333333" GridLines="None"
Height="225px" PageSize="20" ShowHeader="False" style="text-align: center; margin-bottom: 0px;"
Width="1045px">
<PagerSettings Position="TopAndBottom" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" HorizontalAlign="Center" />
<Columns>
<asp:BoundField DataField="County/Zip" HeaderText="Zip Code">
<HeaderStyle BackColor="#FFFFD7" ForeColor="Black" />
<ItemStyle BackColor="#D7E1FF" Height="23px" Width="66px" />
</asp:BoundField>
<asp:BoundField DataField="Premium" DataFormatString="{0:N0}"
HeaderText="Premium" HtmlEncode="False">
<HeaderStyle BackColor="#FFFFD7" ForeColor="Black" />
<ItemStyle BackColor="#D7E1FF" Height="23px" Width="66px" />
</asp:BoundField>
<asp:BoundField DataField="Fire Policies" DataFormatString="{0:N0}"
HeaderText="Fire Policies" HtmlEncode="False">
<HeaderStyle BackColor="#CCFFCC" ForeColor="Black" />
<ItemStyle BackColor="#BFEFFF" Width="66px" />
</asp:BoundField>
<asp:BoundField DataField="Wind/Hail Policies" DataFormatString="{0:N0}"
HeaderText="Wind/Hail Policies" HtmlEncode="False">
<HeaderStyle BackColor="#CCFFCC" ForeColor="Black" />
<ItemStyle BackColor="#BFEFFF" Width="66px" />
</asp:BoundField>
<asp:BoundField DataField="Other Policies" DataFormatString="{0:N0}"
HeaderText="Other Policies" HtmlEncode="False">
<HeaderStyle BackColor="#CCFFCC" ForeColor="Black" />
<ItemStyle BackColor="#BFEFFF" Width="66px" />
</asp:BoundField>
<asp:BoundField DataField="Total Policies" DataFormatString="{0:N0}"
HeaderText="Total Policies" HtmlEncode="False">
<HeaderStyle BackColor="#CCFFCC" ForeColor="Black" />
<ItemStyle BackColor="#BFEFFF" Width="66px" />
</asp:BoundField>
<asp:BoundField DataField="Fire Losses" DataFormatString="{0:N0}"
HeaderText="Fire Losses" HtmlEncode="False">
<HeaderStyle BackColor="#FFEEDD" ForeColor="Black" />
<ItemStyle BackColor="#D7E1FF" Width="66px" />
</asp:BoundField>
<asp:BoundField DataField="Wind/Hail Losses" DataFormatString="{0:N0}"
HeaderText="Wind/Hail Losses" HtmlEncode="False">
<HeaderStyle BackColor="#FFEEDD" ForeColor="Black" />
<ItemStyle BackColor="#D7E1FF" Width="66px" />
</asp:BoundField>
<asp:BoundField DataField="Other Losses" DataFormatString="{0:N0}"
HeaderText="Other Losses" HtmlEncode="False">
<HeaderStyle BackColor="#FFEEDD" ForeColor="Black" />
<ItemStyle BackColor="#D7E1FF" Width="66px" />
</asp:BoundField>
<asp:BoundField DataField="Total Losses" DataFormatString="{0:N0}"
HeaderText="Total Losses" HtmlEncode="False">
<HeaderStyle BackColor="#FFEEDD" ForeColor="Black" />
<ItemStyle BackColor="#D7E1FF" Width="66px" />
</asp:BoundField>
<asp:BoundField DataField="Fire Ratios" DataFormatString="{0:p0}"
HeaderText="Fire Ratios">
<HeaderStyle BackColor="#E7DDEE" ForeColor="Black" />
<ItemStyle BackColor="#BFEFFF" Width="66px" />
</asp:BoundField>
<asp:BoundField DataField="Wind/Hail Ratios" DataFormatString="{0:p0}"
HeaderText="Wind/Hail Ratios">
<HeaderStyle BackColor="#E7DDEE" ForeColor="Black" />
<ItemStyle BackColor="#BFEFFF" Width="66px" />
</asp:BoundField>
<asp:BoundField DataField="Other Ratios" DataFormatString="{0:p0}"
HeaderText="Other Ratios">
<HeaderStyle BackColor="#E7DDEE" ForeColor="Black" />
<ItemStyle BackColor="#BFEFFF" Width="66px" />
</asp:BoundField>
<asp:BoundField DataField="Total Ratios" DataFormatString="{0:p0}"
HeaderText="Total Ratios">
<HeaderStyle BackColor="#E7DDEE" ForeColor="Black" />
<ItemStyle BackColor="#BFEFFF" Width="66px" />
</asp:BoundField>


</Columns>
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" HorizontalAlign="Center" />
<EditRowStyle BackColor="#999999" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:GridView>
</ItemTemplate>

<FooterTemplate>
<%#GetTotal()%>

</FooterTemplate>

</asp:TemplateField>


</Columns>
<FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
<PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
 
Back
Top