Reputation: 590
I'm using Visual Web Developer 2008 Express Edition and I need your assistance since I'm new to it. I want to insert a record into my listview control of my asp.net webpage using c# or vb.net codes. Here's how it works, if I have four textboxes and I'm going to fill each textboxes so I click a command button I want to insert the value of each textboxes into the listview control. Please guide on how to do this. Thank you and I appreciate your help.
Upvotes: 1
Views: 2408
Reputation: 3557
What you are looking for is Data Binding, there is a myriad of Exemple to start form, here some exemples
Update :
Here some vb.net code to help you, I did not test it, it's just to show you the principle.
private Class person
public FirstName as string
public LastName as string
public Address as string
end class
So you could do something like this in your button Click event
Protected Sub Add_Click(ByVal sender As Object,
ByVal e As System.EventArgs) Handles Add.Click
'create the new object
dim newPerson as person = new person
newPerson.FirstName = FirstNameTextBox.text
newPerson.LastName = LastNameTextBox.text
newPerson.Address = AddressTextBox.text
'Get or create a list
dim personList As List(Of person) = Session("personList")
if personList is nothing then
personList = new List(Of person)
end if
'add it to a list and save
personList.Add(newPerson )
Session("personList") = personList
'Bind the list
personListView.DataSource = personList
personListView.Databind()
end sub
Upvotes: 1