Sub FillItemsList() Dim connectionString As String = "Data Source=.;Initial Catalog=Shop;integrated security=true" Dim dt As New DataTable() Using connection As New SqlConnection(connectionString) Dim sql As String = "SELECT PhoneName,PhonePrice FROM SmartPhones" Using adapter As New SqlDataAdapter(sql, connection) adapter.Fill(dt) End Using End Using ListBox1.DataSource = dt ListBox1.DataTextField = "PhoneName" ListBox1.DataValueField = "PhonePrice" ListBox1.DataBind() End Sub Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load Label2.Text = Request.QueryString("Name").ToString() If Not Page.IsPostBack Then FillItemsList() End If End Sub Protected Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged sum = 0 'reset sum to 0 For Each i As Integer In ListBox1.GetSelectedIndices Dim CurrentItem As ListItem = ListBox1.Items(i) sum = sum + CInt(CurrentItem.Value) Items1 = Items1 + " | " + CStr(CurrentItem.Text) Next Label3.Text = Items1 Label1.Text = sum End Sub
<asp:ListBox ID="ListBox1" runat="server" SelectionMode="Multiple" autopostback="true"</asp:ListBox>
PhonePrice
SmartPhones
ID
SELECT
ListBox1.DataValueField = "ID"
Dim sql As String = "SELECT CAST(ID As varchar(10)) + '-' + CAST(PhonePrice As varchar(10)) As ID, PhoneName FROM SmartPhones"...ListBox1.DataValueField = "ID"...sum = sum + CInt(CurrentItem.Value.Split("-"c)(1))
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)