SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast mikevtss's Avatar
    Join Date
    Jul 2006
    Posts
    56
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Paging Declare error?

    Hello
    im trying to get paging going in a datalist... im getting the following error..
    in line 17.... i dont this declared anywhere else in the page...

    i dont no if im going the right way about it..

    Code:
    Compiler Error Message: BC30260: 'cartPager' is already declared as 'Protected Dim WithEvents cartPager As System.Web.UI.HtmlControls.HtmlGenericControl' in this class.
    
    Source Error:
    
     
    
    Line 15: Dim IsForEmail As Boolean = false
    Line 16: Dim pds As PagedDataSource
    Line 17: Protected cartPager As System.Web.UI.HtmlControls.HtmlGenericControl 
    Line 18: 
    Line 19: Sub Page_Load(s As Object, e As EventArgs)
    my code


    Code:
    <%@ Import Namespace="System.Data.OleDb" %>
    <%@ Import Namespace="System.Web.Mail" %>
    <%@ Import Namespace="System.Data" %>
    <%@ Import Namespace="System.IO" %>
    <%@ Import Namespace="System.Data.SqlClient" %>
    <html>
    <head>
    <title>Coast to Coast Order</title>
    <script runat="server" language="VB">
    Dim objConn As New OleDbConnection(ConfigurationSettings.AppSettings("DSN"))
    Dim objDA As OleDbDataAdapter
    Dim objDS As New DataSet()
    Dim objDR As DataRow
    Dim objCartDT As DataTable
    Dim IsForEmail As Boolean = false
    Dim pds As PagedDataSource
    Protected cartPager As System.Web.UI.HtmlControls.HtmlGenericControl 
    
    Sub Page_Load(s As Object, e As EventArgs)
    	
    		pds = New PagedDataSource()
    		
    		pds.AllowPaging = True
    		pds.PageSize = 5
    
    		if (Not Request.QueryString("Page") Is Nothing ) then
    			pds.CurrentPageIndex = Integer.Parse(Request.QueryString("Page"))
    		
    		
    		if pds.PageCount > 0 then
    		if objDs.Tables(0).Rows.Count > 0 then
    			
    			Dim count As Integer = 0
    				
    				while count < pds.PageCount
      
    				  if count = pds.CurrentPageIndex then
    					  cartPager.InnerHTML = cartPager.InnerHTML & (count+1).toString() & "&nbsp;"
    				  else
    					  cartPager.InnerHTML = cartPager.InnerHTML & "<a href=""?Page=" & (count+1).toString() & "">" & (count+1).toString() & "</a>&nbsp;"
    				  end if
      
    				  counter=(counter+1)
      
    			  loop next
      
    		  end if
    
    		END IF
    		END IF
    
    		If Not IsPostBack Then
    		pnlShowCart.Visible = False
    
    		objDA = New OleDbDataAdapter("SELECT * FROM tblProdMast", objConn)
    		objDA.Fill(objDS, "Store")
    		
    		End If
    		
    		pds.DataSource = objDS
    		
    		dlItems.DataSource = pds
    		dlItems.DataBind()
    		
    	If ( NOT Session("Cart") Is Nothing ) Then
    		objCartDT = cType(Session("Cart"), DataTable)
    	Else
    		objCartDT = New DataTable("Cart")
    		objCartDT.Columns.Add("CartID", GetType(Integer))
    		objCartDT.Columns("CartID").AutoIncrement = True
    		objCartDT.Columns("CartID").AutoIncrementSeed = 1
    		objCartDT.Columns.Add("ItemID", GetType(Integer))
    		objCartDT.Columns.Add("QtyAvailable", GetType(Integer))
    		objCartDT.Columns.Add("Item", GetType(String))
    		objCartDT.Columns.Add("Code", GetType(String))
    		objCartDT.Columns.Add("Packing", GetType(String))
    		objCartDT.Columns.Add("Cost", GetType(Decimal))
    		Session("Cart") = objCartDT
    	End If		
    End Sub
    
    
    
    Sub AddToCart(s As Object, e As DataListCommandEventArgs)
    	pnlShowItems.Visible = False
    	pnlShowCart.Visible = True
    
    	Dim ItemID As Integer = dlItems.DataKeys(e.Item.ItemIndex)
    	Dim objItemInfo As DataSet = FindItem(ItemID)
    
    	Dim blnMatch As Boolean = False
    	
    	For Each objDR In objCartDT.Rows
    		If objDR("ItemID") = ItemID Then
    			objDR("QtyAvailable") += 1
    			blnMatch = True
    			Exit For
    		End If
    	Next
    	
    	If Not blnMatch Then
    		objDR = objCartDT.NewRow()
    		objDR("ItemID") = ItemID
    		objDR("Item") = objItemInfo.Tables("ItemInfo").Rows(0).Item("Description")
    		objDR("Code") = objItemInfo.Tables("ItemInfo").Rows(0).Item("Code")
    		objDR("Packing") = objItemInfo.Tables("ItemInfo").Rows(0).Item("Comment")
    		objDR("QtyAvailable") = 1
    		objDR("Cost") = objItemInfo.Tables("ItemInfo").Rows(0).Item("SalesPrice5")
    		objCartDT.Rows.Add(objDR)
    	End If
    
    	BindCart()
    End Sub
    
    Function FindItem(ItemID As Integer) As DataSet
    	Dim objItemInfo As New Dataset()
    
    	objDA = New OleDbDataAdapter("SELECT * FROM tblProdMast WHERE ItemID=" & ItemID, objConn)
    	objDA.Fill(objItemInfo, "ItemInfo")
    
    	Return objItemInfo
    End Function
    
    Function GetItemTotal() As Decimal
    	Dim decRunningTotal As Decimal = 0
    
    	For Each objDR In objCartDT.Rows
    		decRunningTotal += Decimal.Round(objDR("Cost") * objDR("QtyAvailable"), 2)
    	Next
    
    	Return decRunningTotal
    End Function
    
    Sub dgCart_Edit(s As Object, e As DataGridCommandEventArgs)
    	dgCart.EditItemIndex = e.Item.ItemIndex
    
    	BindCart()
    End Sub
    
    Sub dgCart_Cancel(s As Object, e As DataGridCommandEventArgs)
    	dgCart.EditItemIndex = -1
    
    	BindCart()
    End Sub
    
    Sub dgCart_Update(s As Object, e As DataGridCommandEventArgs)
    
    	Dim txtQuantity As TextBox
    	Dim intCartID As Integer
    
    	intCartID = dgCart.DataKeys(e.Item.ItemIndex)
    	txtQuantity = e.Item.FindControl("txtQuantity")
    
    	For Each objDR In objCartDT.Rows
    		If objDR("CartID") = intCartID Then
    			objDR("QtyAvailable") = Int32.Parse(txtQuantity.Text)
    			Exit For
    		End If
    	Next
    
    	dgCart.EditItemIndex = -1
    
    	BindCart()
    End Sub
    
    Sub BindCart()
    	dgCart.DataSource = objCartDT
    	dgCart.DataBind()
    
    	lblTotal.Text = "$" & GetItemTotal()
    End Sub
    
    Sub dgCart_Delete(s As Object, e As DataGridCommandEventArgs)
    	objCartDT.Rows(e.Item.ItemIndex).Delete()
    
    	BindCart()
    End Sub
    
    Sub ContinueShopping(s As Object, e As EventArgs)
    	pnlShowCart.Visible = False
    	pnlShowItems.Visible = True
    End Sub
    
    Sub CheckOut(s As Object, e As EventArgs)
    	' Save the cart here to the database or where ever you want to retrieve your orders from
    
    	EmailDataGrid()
    End Sub
    
    Sub EmailDataGrid()
    
    	dgCart.Columns.RemoveAt(1)
    	dgCart.Columns.RemoveAt(0)
    	
    	BindCart()
    	
    	Dim SB as New StringBuilder()
    	Dim SW as New StringWriter(SB)
    	Dim htmlTW as New HtmlTextWriter(SW)
    	dgCart.RenderControl(htmlTW)
    
    	Dim dataGridHTML as String = SB.ToString()
    
    	Dim objMM as New MailMessage()
    
    	'Set the properties
    	objMM.To = "My email Addy"
    	objMM.From = "Mail Server"
    
    	'Send the email in HTML format
    	objMM.BodyFormat = MailFormat.Html
    
    	'Set the subject
    	objMM.Subject = "Internet Order"
    
    	'Set the body - use VbCrLf to insert a carriage return
    	objMM.Body = "<font face=""Verdana""> Below is the new order " & dataGridHTML
    
    	SmtpMail.Send(objMM)
    
    	Response.Write("<i>Email sent to " & "mike" & "!</i>")
    End Sub
    
    Sub Logout(s As Object, e As EventArgs)
    
    FormsAuthentication.SignOut()
    Response.Redirect("login.aspx")
    
    End Sub
    
    Private Sub dgCart_ItemDataBound(ByVal sender As Object, ByVal e As DataGridItemEventArgs)
       If (  ( IsForEmail ) ANDAlso ( e.Item.ItemType = ListItemType.Footer ) ) Then
       Dim dgLabel As Label = cType(e.Item.FindControl("Label1"), Label)
       
       If ( NOT dgLabel Is Nothing ) Then
    	 dgLabel.Text = txtBox.Text
       End If
    End If
    
    End Sub
    
    </script>
    </head>
    <body>
    <form runat="server">
    
    
    
    <table width="100%" border="0" cellspacing="0" cellpadding="10" algin="center">
    <tr>
    <td valign="top">
    <asp:Panel id="pnlShowItems" runat="server">
    <h1>Coast to Coast Order Page</h1>
    <asp:DataList id="dlItems" runat="server" DataKeyField="ItemID" OnEditCommand="AddToCart">
    <ItemTemplate>
    <table width="400" border="0" cellspacing="0" cellpadding="0" >
    <td width="350">
    	
    	<asp:Image ID="ProductImage" runat="server" ImageUrl='<%# Eval("Code", "Images/{0}01.jpg") %>' AlternateText="Product" ToolTip="Product" /><br/>
    	<strong><%# Container.DataItem("Code") %></strong><br />
    	<%# Container.DataItem("Description") %><br />
    	<strong><%# Container.DataItem("Comment") %></strong><br />
    	<strong>Cost: $<%# Container.DataItem("SalesPrice5") %></strong><br /><br />
    	<asp:Button id="btnAddToCart" runat="server" Text="Add To Cart" CommandName="Edit" />
    	
    
    </td>
    <tr>
    <td colspan="2" width="400"><hr noshade height="1" /></td>
    </tr>
    </table>
    </ItemTemplate>
    </asp:DataList>
    <div id="cartPager" runat="server"></div>
    </asp:Panel>
    <asp:Panel id="pnlShowCart" runat="server">
    	<h1>View Cart</h1>
    	<asp:DataGrid id="dgCart" runat="server" AutoGenerateColumns="false" GridLines="None" CellPadding="3" Width="100%" DataKeyField="CartID" OnCancelCommand="dgCart_Cancel" OnDeleteCommand="dgCart_Delete" OnEditCommand="dgCart_Edit" OnUpdateCommand="dgCart_Update" ShowFooter="true" >
    		<HeaderStyle Font-Name="arial" BackColor="#003366" ForeColor="#FFFFFF" Font-Bold="true" Font-Size="10" />
    		<ItemStyle Font-Name="arial" Font-Size="10" />
    
    			<Columns>
       			<asp:EditCommandColumn EditText="Change Quantity" CancelText="Cancel" UpdateText="Update" />
       			<asp:ButtonColumn ButtonType="LinkButton" Text="Remove" CommandName="Delete" />
       			<asp:BoundColumn DataField="Code" HeaderText="Code" ReadOnly="true" />
       			<asp:BoundColumn DataField="Item" HeaderText="Product Name" ReadOnly="true" />
       			<asp:BoundColumn DataField="Packing" HeaderText="Packing" ReadOnly="true" />
       			<asp:TemplateColumn HeaderText="Quantity">
       				<ItemTemplate>
       					<%# Container.DataItem("QtyAvailable") %>
       				</ItemTemplate>
       				<EditItemTemplate>
       					<asp:TextBox id="txtQuantity" Text='<%# Container.DataItem("QtyAvailable") %>' runat="server" Width="50" />
       				</EditItemTemplate>
       			</asp:TemplateColumn>
       			<asp:TemplateColumn HeaderText="Cost">
       				<ItemTemplate>
       					<%# Container.DataItem("Cost") %>
       				</ItemTemplate>
       				<FooterTemplate>
       				   <asp:Label ID="Label1" runat="server"></asp:Label>
       				</FooterTemplate>
       			</asp:TemplateColumn>
       		</Columns>
       	</asp:DataGrid>
       <asp:TextBox ID="txtBox" Runat="server" />
       <p align="right"><strong>Total: <asp:Label id="lblTotal" runat="server" /></strong></p>
       <p align="right"><asp:LinkButton id="lbContinue" Text="Continue Shopping" runat="server" OnClick="ContinueShopping" />
       | <asp:LinkButton id="lbCheckOut" Text="Checkout" runat="server" OnClick="CheckOut" /> |
       <asp:LinkButton id="lbLogOut" Text="Log Out" OnClick="Logout" runat="server" /></p>
       </asp:Panel>
       </td>
       </tr>
       </table>
       
       </form>
       </body>
       </html>

  2. #2
    SitePoint Author silver trophybronze trophy
    wwb_99's Avatar
    Join Date
    May 2003
    Location
    Washington, DC
    Posts
    10,576
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    If you make a control ided as cartPager in your .aspx file, it is already declared on the page.

  3. #3
    SitePoint Enthusiast mikevtss's Avatar
    Join Date
    Jul 2006
    Posts
    56
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    im not shore if i understand what you mean.....

  4. #4
    ALT.NET - because we need it silver trophybronze trophy dhtmlgod's Avatar
    Join Date
    Jul 2001
    Location
    Scotland
    Posts
    4,836
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You don't need the line that is throwing the error.

  5. #5
    SitePoint Enthusiast mikevtss's Avatar
    Join Date
    Jul 2006
    Posts
    56
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i get this error in line 40



    Code:
    Compiler Error Message: BC30201: Expression expected.
    
    Source Error:
    
     
    
    Line 38: 					  cartPager.InnerHTML = cartPager.InnerHTML & (count+1).toString() & "&nbsp;"
    Line 39: 				  else
    Line 40: 					  cartPager.InnerHTML = cartPager.InnerHTML & "<a href=""?Page=" & (count+1).toString() & "">" & (count+1).toString() & "</a>&nbsp;"
    Line 41: 				  end if
    Line 42:


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •