473,769 Members | 6,203 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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("report level") = Session("availa bilityrptlevel" )
Session("sporti nggoods") = Session("sg_sku ")
Session("le_wid gets") = Session("le_sku ")
Session("ISP_wi dgets") = Session("ISP_sk u")

Dim ConnectionStrin g As String = Session("Connec tString")
Dim myConnection As New SqlConnection(C onnectionString )
Dim cmdFAAvailabili ty As New
SqlCommand("sp_ ASP_fa_availabi lity_new3", myConnection)
cmdFAAvailabili ty.CommandType = CommandType.Sto redProcedure

Dim prmfaavailabili ty As New SqlParameter
prmfaavailabili ty.ParameterNam e = "@availabilityr ptlevel"
prmfaavailabili ty.SqlDbType = SqlDbType.VarCh ar
prmfaavailabili ty.Value = Session("availa bilityrptlevel" )
cmdFAAvailabili ty.Parameters.A dd(prmfaavailab ility)

Dim prmsg_sku As New SqlParameter
prmsg_sku.Param eterName = "@sg_sku"
prmsg_sku.SqlDb Type = SqlDbType.Int
prmsg_sku.Value = Session("sg_sku ")
cmdFAAvailabili ty.Parameters.A dd(prmsg_sku)

Dim prmle_sku As New SqlParameter
prmle_sku.Param eterName = "@le_sku"
prmle_sku.SqlDb Type = SqlDbType.Int
prmle_sku.Value = Session("le_sku ")
cmdFAAvailabili ty.Parameters.A dd(prmle_sku)

Dim prmISP_AFW As New SqlParameter
prmISP_AFW.Para meterName = "@isp"
prmISP_AFW.SqlD bType = SqlDbType.VarCh ar
prmISP_AFW.Valu e = Session("ISP_wi dgets")
cmdFAAvailabili ty.Parameters.A dd(prmISP_AFW)

Dim prmSG_sts As New SqlParameter
prmSG_sts.Param eterName = "@sg_sts"
prmSG_sts.SqlDb Type = SqlDbType.VarCh ar
prmSG_sts.Value = Session("SG_sts ")
cmdFAAvailabili ty.Parameters.A dd(prmSG_sts)

Dim prmLE_sts As New SqlParameter
prmLE_sts.Param eterName = "@le_sts"
prmLE_sts.SqlDb Type = SqlDbType.VarCh ar
prmLE_sts.Value = Session("LE_sts ")
cmdFAAvailabili ty.Parameters.A dd(prmLE_sts)

Try
Dim daGetAvailabili ty As New
SqlDataAdapter( cmdFAAvailabili ty)
Dim dsAvailability As New DataSet
daGetAvailabili ty.Fill(dsAvail ability, "zproduct")

If daGetAvailabili ty.Fill(dsAvail ability, "zproduct") >
0 Then
Label4.ForeColo r = Color.Black
Label4.Text = ""
Me.GridView1.Vi sible = True
Me.GridView1.Da taSource =
dsAvailability. Tables("zproduc t")
Me.GridView1.Da taBind()
Else
Select Case Session("btnSel ect")
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.Vi sible = False
Me.Label4.ForeC olor = Color.Red
End If
Catch SQLexc As SqlException

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

Dim ErrorMessage = "The error description is as
follows: " & SQLexc.ToString ()
mail.From = New MailAddress(ste mp)
mail.To.Add("ad ***********@myd omain.com")
mail.Subject = "Error in widget.com application"
mail.Priority = MailPriority.Hi gh
String.Format(" HTML")
mail.Body = ErrorMessage
Dim SmtpMail As New SmtpClient(Sess ion("MyExchange Server"))
SmtpMail.Send(m ail)

Label3.Text = ""
Label4.Text = ""
Label4.ForeColo r = Color.Red
Label4.Text = Label4.Text + SQLexc.Message. ToString()
Catch ex As Exception
Label3.Text = ""
Label4.ForeColo r = Color.Red
Label4.Text = "There was a problem retrieving data for
this report. "
Finally
Me.SqlConnectio n1.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 CustomersGridVi ew_RowDataBound (ByVal sender As Object, ByVal e As
GridViewRowEven tArgs)
If e.Row.RowType = DataControlRowT ype.Footer Then
Dim rows As Integer
rows = Me.GridView1.Ro ws.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="Tru e"
OnRowDataBound= "CustomersGridV iew_RowDataBoun d" AutoGenerateCol umns="False">
<FooterStyle BackColor="Gain sboro" />
<Columns>
<asp:BoundFie ld DataField="Prod Cd"
HeaderText="Pro d Cd" />
<asp:BoundFie ld DataField="Desc ription"
HeaderText="Des cription" />
<asp:BoundFie ld DataField="Pric e"
DataFormatStrin g="{0:C}" HeaderText="Pri ce" HtmlEncode="Fal se" >
<ItemStyle HorizontalAlign ="Right" />
</asp:BoundField>
<asp:BoundFie ld DataField="free stock"
HeaderText="Fre e Stock" >
<ItemStyle HorizontalAlign ="Right" />
</asp:BoundField>
<asp:BoundFie ld DataField="Note "
HeaderText="Not e" />
</Columns>
<RowStyle BackColor="Mocc asin" />
<HeaderStyle BackColor="Gain sboro" />
<AlternatingRow Style BackColor="Papa yaWhip" />
</asp:GridView>
In debugging, I have a break point on:

If daGetAvailabili ty.Fill(dsAvail ability, "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_avail ability_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 2115
On Jun 5, 10:27 pm, Blasting Cap <goo...@christi an.netwrote:
>
I think the onrowdatabound is the problem, but not sure how to fix it,
No. The problem is very simple:

daGetAvailabili ty.Fill(dsAvail ability, "zproduct")
If daGetAvailabili ty.Fill(dsAvail ability, "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...@christi an.netwrote:
>I think the onrowdatabound is the problem, but not sure how to fix it,

No. The problem is very simple:

daGetAvailabili ty.Fill(dsAvail ability, "zproduct")
If daGetAvailabili ty.Fill(dsAvail ability, "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
9356
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 GridView.Visible = True. I press HIDE and the GridView disappears as expected. After it I press SHOW and the GridView doesn't show.
1
21472
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 the grid). Desired aciton is then taken in response to the button_onclick event relevant to the row in which the checked checkboxes exist. Unfortunate Outcome: Each checkbox returns false for its attribute:checked whether the user has placed a...
0
4666
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 and also get the datakey (in my case personid) of the the rows selected. Please point me in the right direction. This is what i have so far but i have problem accessing the child gridview in the button click event Cheers, Shilpa. <asp:GridView...
2
2830
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 comprising each report. I want the user to be able to select an arbitrary collection of report files and have them emailed by clicking an "Email selected files" button. Everything displays properly, including the checkboxes for each child row (each...
1
4519
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 checkbox is checked, all of the rows in the GridView are checked, if this checkbox is unchecked, all of the rows in the GridView are unchecked. This checking/unchecking of the checkboxes in the GridView is handled by a JavaScript method: function...
2
5339
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 what hotmail web UI is doing now (having the option of selecting multiple rows (using the checkbox provided) and perform a set of operations on them)
1
1846
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 event to check for the number of rows. But the problem is that the user can update a field on my form, which reduces the number of rows in the gridview, because the gridview SELECT statement no longer finds the records when their flag has been set...
6
1985
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 control and in the gridview_RowDataBound event I have string DiscDescrip = Convert.ToString((e.Row.Cells.FindControl("txbxDiscgv") as TextBox ).Text); This returns what was initially loaded in the textbox but not what I had just changed it...
3
5211
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 excel on every way : 1. I disabled the allowpaging in gridview and got and error messages like : System.OutOfMemoryException Was Thrown 2. My idea is to store row in gridview to virtable per pages. I create virtable as Table. Added row to virtable...
0
10211
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10045
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9994
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9863
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8872
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6673
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5299
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3562
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.