Datalist conversion to ListView

Discussion in 'Databases' started by dm3lions, Oct 24, 2009.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. Hi all,

    Please can anyone help me with converting the itemdatabound and itemcommand events in a datalist to a listview? I cannot find out anywhere how to replace the e.item.dataitem code so it is compatible with the listview. Any help would be massively appreciated. The reason I want to do this is to add paging to a products table which has a linksbutton to add the item to a basket and the tutorials utlised a datalist.

    Thanks.

    Protected Sub ListView1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ListViewItemEventArgs) Handles ListView1.ItemDataBound
    If e.Item.ItemType = ListItemType.Item OrElse _
    e.Item.ItemType = ListItemType.AlternatingItem Then

    Dim rpt As Repeater = DirectCast(e.Item.FindControl("Repeater1"), Repeater)

    Dim ItemID As HiddenField = New HiddenField
    Dim ItemName As HiddenField = New HiddenField

    If e.Item.ItemType = ListViewItemType.DataItem Then
    Dim ID As Label = _
    CType(e.Item.FindControl("MenuItemID"), Label)
    End If

    ItemID.ID = "ItemID"
    ItemName.ID = "ItemName"

    ItemID.Value = e.Item.DataItem("MenuItemID")
    ItemName.Value = e.Item.DataItem("ItemName")

    rpt.Controls.Add(ItemID)
    rpt.Controls.Add(ItemName)

    End If
    End Sub
    Protected Sub Repeater1_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.RepeaterCommandEventArgs)

    Dim rpt As Repeater = DirectCast(source, Repeater)

    Dim IDControl As HiddenField = DirectCast(rpt.FindControl("ItemID"), HiddenField)
    Dim NameControl As HiddenField = DirectCast(rpt.FindControl("ItemName"), HiddenField)
    Dim ItemID As Integer = Convert.ToInt32(IDControl.Value)
    Dim ItemName As String = NameControl.Value

    Dim ItemSize As String = e.CommandName.ToString()
    Dim ItemPrice As Decimal = Convert.ToDecimal(e.CommandArgument)

    StoredShoppingCart.InsertItem(ItemID, ItemName, ItemSize, 1, ItemPrice)

    Label1.Text = String.Format("{0} added to the shopping cart", _
    ItemName)

    End Sub
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page