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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Repeater question

Status
Not open for further replies.

vincentw56

IS-IT--Management
Oct 10, 2002
47
0
0
US
Okay I having been trying to figure this out. How can I get the actual data after getting the repeaters item index? What I have is a shopping cart that builds a custom listing. I need to be able to get the price, part number, and product title from the repeater. These items are custom built by the program so they don't really reside in the database. I can get the repeaters item index number just fine when I click on the add to cart link, but how do I get the repeaters actual data? Any help would be appreciated. Thanks.

Vincent
 
can u post some code?

are you adding the data to a Listitem box? if so are you setting the text to the value you want, and the index as the Listitem index?

George Oakes
Goakes@TiresPlus.com = Programmer
George@1-Specialday.com = Mobile DJ
Check out this awsome .Net Resource!
 
Here is the ASPX:

Code:
<form id=&quot;frmproduct&quot; runat=&quot;server&quot;>
					<asp:repeater id=&quot;rpProducts&quot; runat=&quot;server&quot; onitemcommand=&quot;rpProducts_ItemCommand&quot;>
						<itemtemplate>
							<hr style=&quot;BORDER-RIGHT: #cccccc 5px solid; BORDER-TOP: #cccccc 5px solid; BORDER-LEFT: #cccccc 5px solid; WIDTH: 595px; BORDER-BOTTOM: #cccccc 5px solid&quot;>
							<p class=&quot;prodtitle&quot;><%# DataBinder.Eval(Container.DataItem, &quot;fldTitle&quot;) %></p>
							<div style=&quot;FLOAT: left; WIDTH: 390px&quot; class=&quot;proddesc&quot;><%# DataBinder.Eval(Container.DataItem, &quot;fldDescription&quot;) %></div>
							<div style=&quot;FLOAT: left; WIDTH: 205px&quot;><img src='<%# DataBinder.Eval(Container.DataItem, &quot;fldPicture&quot;) %>'/></div>
							<div style=&quot;clear: both&quot;>
								<div style=&quot;FLOAT: left; WIDTH: 145px&quot; class=&quot;prodprice&quot;><b>Price:</b>
									<%# DataBinder.Eval(Container.DataItem, &quot;fldPrice&quot;, &quot;{0:c}&quot;) %>
								</div>
								<div style=&quot;FLOAT: left; WIDTH: 205px&quot; class=&quot;prodprice&quot;><b>Part #:</b>
									<%# DataBinder.Eval(Container.DataItem, &quot;fldPartNo&quot;) %>
								</div>
								<div style=&quot;FLOAT: left; WIDTH: 245px&quot; class=&quot;prodprice&quot;>
									<asp:linkbutton runat=&quot;server&quot; commandname=&quot;AddToCart&quot; id=&quot;lbAddToCart&quot;>Add to Cart</asp:linkbutton></div>
								</div>
						</itemtemplate>
					</asp:repeater></form>

Here is the code:

Code:
Imports System.Data
Imports System.Data.OleDb

Public Class prod
    Inherits System.Web.UI.Page

    Dim dbPath As String = Server.MapPath(&quot;/kmwperformance/db/kmwperfdata.mdb&quot;)


#Region &quot; Web Form Designer Generated Code &quot;

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub
    Protected WithEvents rpProducts As System.Web.UI.WebControls.Repeater
    Protected WithEvents lblError As System.Web.UI.WebControls.Label
    Protected WithEvents rpHeader As System.Web.UI.WebControls.Repeater
    Protected WithEvents frmproduct As System.Web.UI.HtmlControls.HtmlForm
    Protected WithEvents rpTest As System.Web.UI.WebControls.Repeater
    Protected WithEvents lblTitle As System.Web.UI.WebControls.Label
    Protected WithEvents lbAddToCart As System.Web.UI.WebControls.ImageButton

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

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

        ' Get the values passed from another page
        Dim strSQL, strCat, strMake, strModel, strYear As String

        strCat = Request.QueryString(&quot;c&quot;) 'Category
        strMake = Request.QueryString(&quot;m&quot;) 'Make
        strModel = Request.QueryString(&quot;l&quot;) 'Model
        strYear = Request.QueryString(&quot;y&quot;) 'Year

        If strCat <> &quot;&quot; Then 'Check to see if there is a category
            If strCat <> &quot;1&quot; Then
                Call GetProducts(strCat, strMake, strModel, strYear)
            Else
                Call GetProductsBrackets(strCat, strMake, strModel, strYear)
            End If

        Else

            lblError.Text = &quot;Sorry, there was a problem processing this page. Please click on a menu item on the left to get a product listing.&quot;

        End If
    End Sub

    Sub GetProductsBrackets(ByVal strCat As String, ByVal strMake As String, ByVal strModel As String, ByVal strYear As String)

        Dim strSQL As String = &quot;SELECT * FROM tblProduct WHERE fldSubCategory = &quot; + strCat
        Dim strConnection As String = &quot;Provider=Microsoft.Jet.OleDb.4.0;data source=&quot; + dbPath
        Dim ojbConnection As New OleDbConnection(strConnection)
        Dim ojbCommand As New OleDbCommand(strSQL, ojbConnection)
        Dim ojbDataAdapter As New OleDbDataAdapter
        Dim dtProduct As New DataTable
        Dim drProduct As DataRow

        Dim iProductRow As Integer

        ojbDataAdapter.SelectCommand = ojbCommand
        ojbDataAdapter.Fill(dtProduct)

        iProductRow = dtProduct.Rows.Count

        Dim strSQL1 As String = &quot;SELECT * FROM tblProduct WHERE (fldSubCategory = 2) AND (fldMake='&quot; + strMake + &quot;') AND (fldModel='&quot; + strModel + &quot;') AND (fldMinYr <=&quot; + strYear + &quot;) AND (fldMaxYr >=&quot; + strYear + &quot;)&quot;
        Dim strConnection1 As String = &quot;Provider=Microsoft.Jet.OleDb.4.0;data source=&quot; + dbPath
        Dim ojbConnection1 As New OleDbConnection(strConnection1)
        Dim ojbCommand1 As New OleDbCommand(strSQL1, ojbConnection)
        Dim ojbDataAdapter1 As New OleDbDataAdapter
        Dim dtBrackets As New DataTable
        Dim drBrackets As DataRow
        Dim iBracketRow As Integer

        ojbDataAdapter1.SelectCommand = ojbCommand1
        ojbDataAdapter1.Fill(dtBrackets)

        iBracketRow = dtBrackets.Rows.Count

        If iProductRow = 0 Or iBracketRow <= 1 Then
            lblError.Text = &quot;Sorry we don't show anything for your vehicle at this time&quot;
        Else
            Dim strBracketTitle(2), strBracketDesc(2), strBracketPrice(2) As String
            Dim strTempTitle, strTempPrice, strTempDesc As String
            Dim iBracketPriceTotal
            Dim iCount As Integer = 1

            For iCount = 1 To 2
                drBrackets = dtBrackets.Rows.Item(iCount - 1)
                strBracketTitle(iCount) = drBrackets.Item(&quot;fldTitle&quot;)
                strBracketDesc(iCount) = drBrackets.Item(&quot;fldDescription&quot;)
                strBracketPrice(iCount) = drBrackets.Item(&quot;fldPrice&quot;)
            Next

            iBracketPriceTotal = Val(strBracketPrice(1)) + Val(strBracketPrice(2))

            iCount = 0

            For iCount = 0 To iProductRow - 1
                drProduct = dtProduct.Rows.Item(iCount)
                drProduct.Item(&quot;fldTitle&quot;) += &quot; for a &quot; + strYear + &quot; &quot; + strMake + &quot; &quot; + strModel
                drProduct.Item(&quot;fldPrice&quot;) += iBracketPriceTotal
                drProduct.Item(&quot;fldDescription&quot;) += &quot;<br /><br />&quot; + strBracketTitle(1) + &quot;<br />&quot; + strBracketDesc(1) + &quot;<br /><br />&quot; + strBracketTitle(2) + &quot;<br />&quot; + strBracketDesc(2)

            Next

            rpProducts.DataSource = dtProduct
            rpProducts.DataBind()
            Call GetCategory(strCat)
        End If

    End Sub

    Sub GetCategory(ByVal strCat)

        Dim strSQL As String = &quot;SELECT * FROM tblSubCategory WHERE fldSubCatID = &quot; + strCat

        Dim strConnection As String = &quot;Provider=Microsoft.Jet.OleDb.4.0;data source=&quot; + dbPath
        Dim ojbConnection As New OleDbConnection(strConnection)
        Dim ojbCommand As New OleDbCommand(strSQL, ojbConnection)

        ojbConnection.Open()
        rpHeader.DataSource = ojbCommand.ExecuteReader()
        rpHeader.DataBind()
        ojbConnection.Close()

    End Sub

    Sub GetProducts(ByVal strCat As String, ByVal strMake As String, ByVal strModel As String, ByVal strYear As String)

        Dim strSQL As String

        If strMake = &quot;&quot; Then
            strSQL = &quot;SELECT * FROM tblProduct WHERE fldSubCategory = &quot; + strCat
        Else
            strSQL = &quot;SELECT * FROM tblProduct WHERE (fldSubCategory = &quot; + strCat + &quot;) AND (fldMake='&quot; + strMake + &quot;') AND (fldModel='&quot; + strModel + &quot;') AND (fldMinYr <=&quot; + strYear + &quot;) AND (fldMaxYr >=&quot; + strYear + &quot;)&quot;
        End If

        Dim strConnection As String = &quot;Provider=Microsoft.Jet.OleDb.4.0;data source=&quot; + dbPath
        Dim ojbConnection As New OleDbConnection(strConnection)
        Dim ojbCommand As New OleDbCommand(strSQL, ojbConnection)
        Dim ojbDataAdapter As New OleDbDataAdapter
        Dim dtProduct As New DataTable

        ojbDataAdapter.SelectCommand = ojbCommand
        ojbDataAdapter.Fill(dtProduct)

        rpProducts.DataSource = dtProduct
        rpProducts.DataBind()
        Call GetCategory(strCat)

    End Sub

    Sub rpProducts_ItemCommand(ByVal sender As Object, ByVal e As RepeaterCommandEventArgs)

	'Add to cart data

    End Sub

End Class

Thanks,
Vincent
 
Okay I figured out a way to do this. I created a ASP Label and put the values in there. I then was able to reference the values from the code. Here is a sample:

ASPX
Code:
<asp:label id=&quot;lblTitle&quot; runat=&quot;server&quot; text='<%# DataBinder.Eval(Container.DataItem, &quot;fldTitle&quot;) %>' />

Code behind
Code:
Dim strTitle As Label = rpProducts.Items(e.Item.ItemIndex).FindControl(&quot;lblTitle&quot;)

That works perfectly. Thanks.

Vincent
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top