如何插入记录使用C#asp.net的ListView控件? [英] How to insert a record into a listview control of asp.net using c#?

查看:83
本文介绍了如何插入记录使用C#asp.net的ListView控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的Visual Web Developer 2008防爆preSS版,我需要你的帮助,因为我是新来的吧。我想记录插入使用C#或vb.net codeS我的asp.net网页我的ListView控件。下面是它如何工作的,如果我有四个文本框和我去填充每个文本框,因此我需要输入一个命令按钮,我想每一个文本框的值插入ListView控件。请如何做到这一点指导。谢谢你,我AP preciate你的帮助。

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.

推荐答案

你所寻找的是的数据绑定,还有为例无数的启动形式,这里的一些exemples

What you are looking for is Data Binding, there is a myriad of Exemple to start form, here some exemples

  • http://www.codeproject.com/KB/webforms/CompleteListView.aspx
  • http://geekswithblogs.net/rashid/archive/2007/09/09/Asp.net-ListView---DataBinding.aspx

更新:

下面一些vb.net code来帮助你,我没有测试它,它只是给你看的原则。

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 

所以你可以做这样的事情在你的按钮的Click事件

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

这篇关于如何插入记录使用C#asp.net的ListView控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆