1

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.

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

3 Comments

@DavRob--------not necessarily databinding, because when you talk about databinding the record comes from your database. All I want is just to add the records directly from your textboxes into the listview control just like we normally did in windows application. How possible is that?
IT' long to explain, but in short, one way of doing this is to write a class with the properties you need. then you will be able create a instance of this class, put it in a collection and bind the collection to the list. If you want to add more than one item, you will have to retrieve and save your collection in the session.
For now its very hard for me to figure it out but if you can provide me a sample code then would be so much better.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.