Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Duplicates in DataList ????????????????????????

Status
Not open for further replies.

qberta1

Programmer
Joined
Apr 27, 2005
Messages
4
Location
US
Hello,

I created a datalist and populate it with products from a proc. Problem is that when I run the application it lists the same product multiple times. I have checked the proc and it does not render duplicates. I cannot figure out why the datalist repeats the products.

It used to work when I had limited data in my tables, but once I appended more data to the tables this problem started. I then went back and deleted the appended data and I still get duplicates.

Any obvious reason why this might be occuring?

Thanks for the help!

Q!
 
can i have the code???

Known is handfull, Unknown is worldfull
 
page cacheing?

"...we both know I'm training to become a cagefighter...see what happens if you try 'n hit me..."
 
Okay The Code:

<%@ OutputCache Duration="6000" VaryByParam="CategoryID" %>
<%@ Register TagPrefix="ASPNETCommerce" TagName="Header" Src="_Header.ascx" %>
<%@ Register TagPrefix="ASPNETCommerce" TagName="Menu" Src="_Menu.ascx" %>
<%@ Page Language="vb" EnableViewState="false" CodeBehind="ProductsList.aspx.vb" AutoEventWireup="false" Inherits="ASPNET.StarterKit.Commerce.ProductsList" %>

<HTML>
<HEAD>
</HEAD>
<body>
<table>
<tr>
<td colspan="2">
code.....
</td>
</tr>
<tr>
<td valign="top">
code...... </td>
<td> <table>
<tr valign="top">
<td nowrap>
<br>
<asp:DataList id="MyList"
RepeatColumns="2" runat="server">
<ItemTemplate>
<table>
<tr>
<td width="25">
</td>
<td>
<a href='ProductDetails.aspx?productID=<%# DataBinder.Eval(Container.DataItem, "ProductID") %>'>

<img src='ProductImages/thumbs/<%# DataBinder.Eval(Container.DataItem, "ProductImage") %>' width="100" height="75" border="0"></a>
</td>
<td>
<a href='ProductDetails.aspx?productID=<%# DataBinder.Eval(Container.DataItem, "ProductID") %>'>
<span class="ProductListHead">
<%# DataBinder.Eval(Container.DataItem, "ModelName") %>
</span>
<br></a>
<span class="ProductListItem">
<b>Special Price: </b>
<%# DataBinder.Eval(Container.DataItem, "UnitCost", "{0:c}") %>
</span>
<br>
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>............................

Code Behind:

Public Class ProductsList
Inherits System.Web.UI.Page
Protected WithEvents MyList As System.Web.UI.WebControls.DataList

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

' Obtain categoryId from QueryString
Dim categoryId As Integer = CInt(Request.Params
("CategoryID"))

' Obtain products and databind to an asp:datalist control
Dim productCatalogue As
ASPNET.StarterKit.Commerce.ProductsDB = New
ASPNET.StarterKit.Commerce.ProductsDB()
MyList.DataSource = productCatalogue.GetProducts
(categoryId)
MyList.DataBind()

End Sub

End Class


-----

Sorry for the mess!

Thanks!


 
Within the productCatalogue.GetProducts Function you may need to check if the returned object is already populated.

Within my applications I use something like this...
Code:
' Ensure the Dataset is not populated more than once.
If (Not IsNothing(DatasetName.Tables("tablename"))) Then
DatasetName.Tables("tablename").Clear()
End If


--
Not until I became a Network Administrator did the error message "See your Network Administrator for assistance" become petrifying.
 
You know this was driving me just about insane. The problem was with the proc. I had it as follows:

exec CMRC_GetPriceRange

Select c.ProductID,
c.ModelName,
UnitCost,
c.ProductImage
from CMRC_Products c
Left Join PriceRange p ON c.ProductID = p.ProductID
WHERE
c.CategoryID = @CategoryID
ORDER BY
ModelName,
ModelNumber

----

Even though it didn't return duplicate values when running through query analyzer it returned duplicates to the datalist. Anyway, I changed it and it now works.

Thanks for the help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top