我是ASP.net的新手,我想以編程方式創建一個動態Listview組件。 我找到了關於如何爲Gridview和Datatable做但不是Listview的例子。可能嗎? 有誰知道一個很好的教程?以編程方式在asp.net中創建列表視圖
0
A
回答
2
試試這個
private void CreateMyListView()
{
// Create a new ListView control.
ListView listView1 = new ListView();
listView1.Bounds = new Rectangle(new Point(10,10), new Size(300,200));
// Set the view to show details.
listView1.View = View.Details;
// Allow the user to edit item text.
listView1.LabelEdit = true;
// Allow the user to rearrange columns.
listView1.AllowColumnReorder = true;
// Display check boxes.
listView1.CheckBoxes = true;
// Select the item and subitems when selection is made.
listView1.FullRowSelect = true;
// Display grid lines.
listView1.GridLines = true;
// Sort the items in the list in ascending order.
listView1.Sorting = SortOrder.Ascending;
//Creat columns:
ColumnHeader column1 = new ColumnHeader();
column1.Text = "Customer ID";
column1.Width = 159;
column1.TextAlign = HorizontalAlignment.Left;
ColumnHeader column2 = new ColumnHeader();
column2.Text = "Customer name";
column2.Width = 202;
column2.TextAlign = HorizontalAlignment.Left;
//Add columns to the ListView:
listView1.Columns.Add(column1);
listView1.Columns.Add(column2);
// Add the ListView to the control collection.
this.Controls.Add(listView1);
}
還是來看看如何處理這個任務是Example
Imports System
Imports System.Drawing
Imports System.Windows.Forms
Public Class listview
Inherits Form
Friend WithEvents btnCreate As Button
Public Sub New()
Me.InitializeComponent()
End Sub
Private Sub InitializeComponent()
btnCreate = New Button
btnCreate.Text = "Create"
btnCreate.Location = New Point(10, 10)
Me.Controls.Add(btnCreate)
Text = "Countries Statistics"
Size = New Size(450, 245)
StartPosition = FormStartPosition.CenterScreen
End Sub
Private Sub btnCreate_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnCreate.Click
Dim lvwCountries As ListView = New ListView
lvwCountries.Location = New Point(10, 40)
lvwCountries.Width = 420
lvwCountries.Height = 160
Controls.Add(lvwCountries)
End Sub
Public Shared Sub Main()
Application.Run(New Exercise)
End Sub
End Class
+1
這是Windows Forms的權利?我想這個問題是圍繞Web表單... – Faiz 2013-07-01 06:40:50
1
基本思路。關鍵概念與GridView
需要的是相同的。
1)您需要在頁面上某處放置ListView
- 容器。
2)此容器需要運行在服務器,所以您的C#代碼(服務器評估)可以將ListView
添加到它。您可以使用兩個示例容器:Panel
和帶runat=server
屬性的標準div
標籤。
3)選擇代碼來創建ListView控件時,將稱爲和如何。我建議你將其定義爲方法,並從任何事件你想如稱之爲:
protected void Page_Load(object sender, EventArgs e)
{
// Call your method here so the ListView is created
CreateListView();
}
private void CreateListView()
{
// Code to create ListView here
}
4)使用下面的代碼在上面的方法來創建ListView
並將其添加到像這樣的容器:
var myListView = new ListView();
containerName.Controls.Add(myListView);
你將需要添加到ListView
的性能它是美觀,對明顯的數據綁定的頂部。
在this page上找到的代碼有一些您最希望使用的示例屬性。
相關問題
- 1. 以編程方式在Android中創建列表視圖項目
- 2. 以編程方式在視圖中創建列
- 3. 基於列以編程方式在Sharepoint中創建樹視圖
- 4. 以編程方式創建視圖
- 5. 以編程方式創建視圖
- 6. WPF以編程方式創建樹視圖itemtemplate /列
- 7. ASP.NET:以編程方式創建CSS類
- 8. 以編程方式在RecyclerView中創建或膨脹視圖OnCreateViewHolder
- 9. 以編程方式創建視頻列表
- 10. 如何以編程方式創建表格視圖?
- 11. 創建具有甘特圖視圖的Sharepoint列表 - 以編程方式
- 12. 以編程方式創建視頻?
- 13. 在Android中以編程方式創建父視圖中的子視圖
- 14. 以編程方式創建流程圖
- 15. ViewPager以編程方式在其中創建recyclerView列表
- 16. 如何在SharePoint中以編程方式創建KPI列表?
- 17. 以編程方式創建帶圓角的圖層列表
- 18. 如何以編程方式創建圖層列表可繪製?
- 19. 以編程方式在PHP中創建Excel圖表
- 20. 以聲明方式或編程方式創建Sharepoint列表?
- 21. 以編程方式快速在視圖之間創建segue
- 22. 以編程方式創建視圖後添加樣式
- 23. 試圖以編程方式創建rightBarButtonItem
- 24. 以編程方式創建繪圖
- 25. 以編程方式創建UML類圖
- 26. 以編程方式創建圖像?
- 27. C#以編程方式創建報表
- 28. 以編程方式創建SQL Server表
- 29. 以編程方式創建表
- 30. 以編程方式創建win表單?
請發佈'Gridview和Datatable'的示例鏈接,以便我們確切地知道你在問什麼。 – Win 2013-02-25 20:08:28