1 Replies - 4790 Views - Last Post: 05 January 2008 - 10:31 AM Rate Topic: -----

#1 cyberstore05  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 5
  • Joined: 04-January 08

Problem Displaying Data Using Repeater Control

Post icon  Posted 05 January 2008 - 09:46 AM

Hi There,
I am trying to display data from an SQL database using the Repeater control in ASP.net, but I’ve run into some difficulty. Primarily, when a user selects an item from a menu, data from an SQL table is displayed using Gridview – this works perfectly ok. Additionally, I want a subset of the Gridview data to be displayed using the Repeater control - this is where I have the problem: the two sets of data are not displayed simultaneously when a menu selection is made. Instead, the data from the previous menu selection is displayed. In short, the Repeater data lags behind the Gridview data.


Sub Page_Load 
	If Not Page.IsPostBack then
	Dim SQLstring As Object
If MenuSearch = "selected item" Then
		SQLString = "SELECT * FROM ProductsTab " & _		 
		   "WHERE OuterCategory = '" & MenuSearch & "' " & _
		"IF OBJECT_ID(N'ProductsDB..BrandsTab') IS NOT NULL " & 	
 		"DROP TABLE BrandsTab " & _
"SELECT Brand, COUNT(*) AS BrandCount INTO BrandsTab FROM ProductsTab " & _			 
		   "WHERE OuterCategory = '" & MenuSearch & "' " & _
		 "GROUP BY Brand "
 		  ……………
	SqlDataSource2.SelectCommand = SQLString
   End If
End Sub 
Note: Data from ProductsTab is displayed in Gridview, data from BrandsTab is displayed in Repeater. The subset of selection from ProductsTab is saved in BrandsTab.
The Repeater code is:-
<asp:Repeater runat="server" id="Repeater1" DataSourceID="SqlDataSourceBrand" OnItemCreated="Repeater1_ItemCreated" >
	<ItemTemplate>
		<asp:Label Text='<%# Eval("Brand") %>' runat="server"/>  
		<br />		
<asp:Label Text='<%# Eval("BrandCount") %>' runat="server"/>	
	</ItemTemplate>
</asp:Repeater>



I hope the above code helps to explain my problem. I would greatly appreciate any help.

Edit: Please use code tags when posting your code :) , Like so => :code:

This post has been edited by PsychoCoder: 05 January 2008 - 10:14 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Problem Displaying Data Using Repeater Control

#2 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1638
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Problem Displaying Data Using Repeater Control

Posted 05 January 2008 - 10:31 AM

For starters you're leaving yourself wide open to a SQL Injection attack, so I took the liberty of changing some items of your connection string to help prevent this from happening (called paramaterized SQL).

Second in your SQL Query you're DROPPING the table (which removes it), then try to add to it again. I made these changes hoping you're using MSSQL and not mySQL, instead of DROP TABLE <table_name> use TRUNCATE TABLE, that removed all current rows without removing the entire table.

Theres more than likely going to be a lag, how long depends on the users system and the database. Here is the code I modified for you, see if that does any good:

Sub Page_Load()
		If Not Page.IsPostBack Then
		End If
		Dim SQLstring As Object
		If MenuSearch = "selected item" Then
			SQLstring = "SELECT * FROM ProductsTab WHERE OuterCategory = @search " & _
			"IF OBJECT_ID(N'ProductsDB..BrandsTab') IS NOT NULL " & _
			"TRUNCATE TABLE BrandsTab " & _
			 "SELECT Brand, COUNT(*) AS BrandCount INTO BrandsTab FROM ProductsTab " & _
			 "WHERE OuterCategory = @search GROUP BY Brand "
			SqlDataSource2.SelectParameters.Add("@search", MenuSearch)
			SqlDataSource2.SelectCommand = SQLstring
		End If
End Sub


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1