473,395 Members | 1,702 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Gridview doubling up rows

I've got a gridview (that I converted over from a datagrid, which had
been working properly), that is doubling up the number of rows returned.
When it was running as a datagrid, the same code sent back the
proper number of rows. The only thing different I am doing is to
display the number of rows returned in the footer of the gridview.

The Bindgrid is as follows:

Sub BindGrid()
Session("reportlevel") = Session("availabilityrptlevel")
Session("sportinggoods") = Session("sg_sku")
Session("le_widgets") = Session("le_sku")
Session("ISP_widgets") = Session("ISP_sku")

Dim ConnectionString As String = Session("ConnectString")
Dim myConnection As New SqlConnection(ConnectionString)
Dim cmdFAAvailability As New
SqlCommand("sp_ASP_fa_availability_new3", myConnection)
cmdFAAvailability.CommandType = CommandType.StoredProcedure

Dim prmfaavailability As New SqlParameter
prmfaavailability.ParameterName = "@availabilityrptlevel"
prmfaavailability.SqlDbType = SqlDbType.VarChar
prmfaavailability.Value = Session("availabilityrptlevel")
cmdFAAvailability.Parameters.Add(prmfaavailability )

Dim prmsg_sku As New SqlParameter
prmsg_sku.ParameterName = "@sg_sku"
prmsg_sku.SqlDbType = SqlDbType.Int
prmsg_sku.Value = Session("sg_sku")
cmdFAAvailability.Parameters.Add(prmsg_sku)

Dim prmle_sku As New SqlParameter
prmle_sku.ParameterName = "@le_sku"
prmle_sku.SqlDbType = SqlDbType.Int
prmle_sku.Value = Session("le_sku")
cmdFAAvailability.Parameters.Add(prmle_sku)

Dim prmISP_AFW As New SqlParameter
prmISP_AFW.ParameterName = "@isp"
prmISP_AFW.SqlDbType = SqlDbType.VarChar
prmISP_AFW.Value = Session("ISP_widgets")
cmdFAAvailability.Parameters.Add(prmISP_AFW)

Dim prmSG_sts As New SqlParameter
prmSG_sts.ParameterName = "@sg_sts"
prmSG_sts.SqlDbType = SqlDbType.VarChar
prmSG_sts.Value = Session("SG_sts")
cmdFAAvailability.Parameters.Add(prmSG_sts)

Dim prmLE_sts As New SqlParameter
prmLE_sts.ParameterName = "@le_sts"
prmLE_sts.SqlDbType = SqlDbType.VarChar
prmLE_sts.Value = Session("LE_sts")
cmdFAAvailability.Parameters.Add(prmLE_sts)

Try
Dim daGetAvailability As New
SqlDataAdapter(cmdFAAvailability)
Dim dsAvailability As New DataSet
daGetAvailability.Fill(dsAvailability, "zproduct")

If daGetAvailability.Fill(dsAvailability, "zproduct") >
0 Then
Label4.ForeColor = Color.Black
Label4.Text = ""
Me.GridView1.Visible = True
Me.GridView1.DataSource =
dsAvailability.Tables("zproduct")
Me.GridView1.DataBind()
Else
Select Case Session("btnSelect")
Case "SG" 'Sporting
Label4.Text = "No Sporting widgets on
Availability List as of " & Year(Now()) & "-" & Month(Now()) & "-" &
Day(Now())
Case "LE" 'Entertainment
Label4.Text = "No Entertainment widgets on
Availability List as of " & Year(Now()) & "-" & Month(Now()) & "-" &
Day(Now())
Case "ISP" 'ISP
Label4.Text = "No ISP widgets on
Availability List as of " & Year(Now()) & "-" & Month(Now()) & "-" &
Day(Now())
Case "SG_STS" 'Sporting Subject-To-Stock
Label4.Text = "No Sporting widgets on
Subject-to-Stock List as of " & Year(Now()) & "-" & Month(Now()) & "-" &
Day(Now())
Case "LE_STS" 'LE Subject-to-Stock
Label4.Text = "No Entertainment widgets on
Subject-to-Stock List as of " & Year(Now()) & "-" & Month(Now()) & "-" &
Day(Now())
End Select
Me.GridView1.Visible = False
Me.Label4.ForeColor = Color.Red
End If
Catch SQLexc As SqlException

Dim mail As New MailMessage()
Dim stemp As String = "me@mydomain.com"

Dim ErrorMessage = "The error description is as
follows: " & SQLexc.ToString()
mail.From = New MailAddress(stemp)
mail.To.Add("ad***********@mydomain.com")
mail.Subject = "Error in widget.com application"
mail.Priority = MailPriority.High
String.Format("HTML")
mail.Body = ErrorMessage
Dim SmtpMail As New SmtpClient(Session("MyExchangeServer"))
SmtpMail.Send(mail)

Label3.Text = ""
Label4.Text = ""
Label4.ForeColor = Color.Red
Label4.Text = Label4.Text + SQLexc.Message.ToString()
Catch ex As Exception
Label3.Text = ""
Label4.ForeColor = Color.Red
Label4.Text = "There was a problem retrieving data for
this report. "
Finally
Me.SqlConnection1.Close()
End Try
End Sub

I also included the code that does different things if I have a SQL
exception, etc.
The Rowdatabound code is:

Sub CustomersGridView_RowDataBound(ByVal sender As Object, ByVal e As
GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.Footer Then
Dim rows As Integer
rows = Me.GridView1.Rows.Count
e.Row.Cells(1).Text = "Total Records: (" & rows & ")"
End If
End Sub
The HTML is:

<asp:GridView ID="GridView1" runat="server"
Font-Size="X-Small" ShowFooter="True"
OnRowDataBound="CustomersGridView_RowDataBound" AutoGenerateColumns="False">
<FooterStyle BackColor="Gainsboro" />
<Columns>
<asp:BoundField DataField="Prod Cd"
HeaderText="Prod Cd" />
<asp:BoundField DataField="Description"
HeaderText="Description" />
<asp:BoundField DataField="Price"
DataFormatString="{0:C}" HeaderText="Price" HtmlEncode="False" >
<ItemStyle HorizontalAlign="Right" />
</asp:BoundField>
<asp:BoundField DataField="freestock"
HeaderText="Free Stock" >
<ItemStyle HorizontalAlign="Right" />
</asp:BoundField>
<asp:BoundField DataField="Note"
HeaderText="Note" />
</Columns>
<RowStyle BackColor="Moccasin" />
<HeaderStyle BackColor="Gainsboro" />
<AlternatingRowStyle BackColor="PapayaWhip" />
</asp:GridView>
In debugging, I have a break point on:

If daGetAvailability.Fill(dsAvailability, "zproduct") 0 Then

and this, and the query run in Query analyzer returns 202 rows. However
a stop point on:

e.Row.Cells(1).Text = "Total Records: (" & rows & ")"

shows the rows variable to be 404, 606, 808, or 1010, and the gridview
has the same number of records in it.
I think the onrowdatabound is the problem, but not sure how to fix it,
since this same code worked just fine in dealing with datagrids. When I
brought in the gridview, I ran them side by side and know that up until
I took out the datagrid (and added the on row databound) the datagrid &
gridview returned the same number of records. When I re-did the code for
the gridview (I had it commented out for the datagrid), I more-or-less
just changed the datagrid to gridview, correcting any errors as I went.

Any ideas why this is getting doubled up? I have a stop point on the
fill, and I believe it's only getting called 1 time, and when I run the
sql code with the parameters in Query Analyzer:
sp_ASP_fa_availability_new3 '10','1','0','0','0','0'

it returns only 202 rows. However, the app is doubling (and more) these
same records.

Any ideas as to what is going on here?

Thanks,

BC
Jun 5 '07 #1
2 2083
On Jun 5, 10:27 pm, Blasting Cap <goo...@christian.netwrote:
>
I think the onrowdatabound is the problem, but not sure how to fix it,
No. The problem is very simple:

daGetAvailability.Fill(dsAvailability, "zproduct")
If daGetAvailability.Fill(dsAvailability, "zproduct") 0 Then

You added rows in to the dsAvailability data set two times.

Use Rows.Count instead

If (dsAvailability.Tables(0).Rows.Count 0) Then
Jun 5 '07 #2
Thank you!! That fixed it. I had been so focused on what "new" was
there, I didn't even look at that.

Alexey Smirnov wrote:
On Jun 5, 10:27 pm, Blasting Cap <goo...@christian.netwrote:
>I think the onrowdatabound is the problem, but not sure how to fix it,

No. The problem is very simple:

daGetAvailability.Fill(dsAvailability, "zproduct")
If daGetAvailability.Fill(dsAvailability, "zproduct") 0 Then

You added rows in to the dsAvailability data set two times.

Use Rows.Count instead

If (dsAvailability.Tables(0).Rows.Count 0) Then

Jun 6 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Miguel Dias Moura | last post by:
Hello, I have a GridView in my page which is created in runtime. It works fine. My page has 2 Asp Buttons: - The HIDE button makes GridView.Visible = False; - The SHOW button makes...
1
by: mercercreek | last post by:
This one should be easy. Hope someone has a clue. Simple Scenario: Gridview with mulitple rows, each row with a checkbox. The user checks boxes of her choice. Clicks a button on the form (not in...
0
by: sharonrao123 | last post by:
hello all, I have a parent gridview company and in this one a nested gridview people, Is it possible to allow the user to select one row or multiple rows from the people gridview using a check box...
2
by: GISmatters | last post by:
I have unbound checkboxes in a nested gridview to allow multi-selection of "child" rows. For context, the parent gridview rows are for large "reports", the child rows are for various specific files...
1
Frinavale
by: Frinavale | last post by:
I'm working on an ASP.NET application using VB.NET for server side code. I have a GridView listing a bunch of stuff. Above the GridView I have a checkbox named "ChkBx_SelectAll". If this...
2
by: Michael | last post by:
It seems that a gridview allows us to delete only a single row at a time. How to extend this functionality to select multiple rows and delete all of the selected rows in a single stroke? just like...
1
by: COHENMARVIN | last post by:
I have a gridview and I need to know the number of rows in it. I find the Page_load and the Gridview_Load events are too early to find out the number of rows. I can use the Gridview_databound...
6
by: =?Utf-8?B?UGF1bA==?= | last post by:
Hi I have a gridview control with a template column that has a textbox and when the control is bound to the datasource the textbox is filled ok. I then change what is in the textbox in the gridview...
3
by: ulai | last post by:
Thanks for your help. It really help to solve my work. But now i have a bigger problem : I had more than 65535 records in gridview divide by 10/pages. And when i tried to export the gridview in...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.