2010-01-08 88 views
1

對於我來說,構建一個控件的最佳方式是什麼,它會像ASP.NET中的Access表一樣工作?用於ASP.NET的表格網格控件

也就是說,我定義了3列。用戶可以添加/編輯/刪除行。它可以是一次一行,沒關係。表單上還有其他字段,與此表格無關。當用戶完成添加信息行後,他們點擊「提交」,並在指向,是當我從控制中獲取所有數據並保存到數據庫(或xml文件或其他)時。

我試着用ListView和/或GridView來構建一些東西,而我似乎無法得到我想要的行爲。任何想法或例子?

+3

您無法使用ListView/GridView實現哪些特定行爲? – 2010-01-08 16:01:18

回答

2

你可能想看看jQuery的jqGrid

Demo here。我在網格操縱方面看到的內容與行編輯有關,但不太瞭解列。

相關SO Posts here

1

在鏈接,可能是有用的:從自己的項目

Using the New ListView Control in ASP.NET 3.5
Eksample:

   <asp:ListView ID="lvList" runat="server" OnLayoutCreated="lvList_LayoutCreated" OnItemDataBound="lvList_OnItemDataBound"> 
        <LayoutTemplate> 
         <table id="tblTest" class="lvtest" cellpadding="0" cellspacing="0"> 
          <tr> 
           <th class="listheader"> 
            <asp:Label ID="lbl1" runat="server" /> 
           </th> 
           <th class="listheader"> 
            <asp:Label ID="lbl2" runat="server" /> 
           </th> 
          </tr> 
          <tr runat="server" id="itemPlaceholder" /> 
         </table> 
        </LayoutTemplate> 
        <EmptyDataTemplate> 
         <tr> 
          <td colspan="2"> 
           <asp:Label ID="lblNotFound" runat="server" OnInit="lblOnInit" /> 
          </td> 
         </tr> 
        </EmptyDataTemplate> 
        <ItemTemplate> 
         <tr class="<%# Container.DataItemIndex % 2 == 0 ? "odd" : "even" %>"> 
          <td class="listcell"> 
           <asp:Literal ID="lit1" runat="server" /> 
          </td> 
          <td class="listcell"> 
           <asp:Literal ID="lit1" runat="server" /> 
          </td> 
         </tr> 
        </ItemTemplate> 
       </asp:ListView> 

事件處理程序:

protected void lvRist_LayoutCreated(object sender, EventArgs e) 
    { 
     SetHeaderValues(); 
    } 


    //For the label when empty text 
     protected void lblOnInit(object sender, EventArgs e) 
    { 
     SetEmptyText(sender); 
    } 



    protected void lvList_OnItemDataBound(object sender, ListViewItemEventArgs e) 
    { 
     if (e.Item.ItemType != ListViewItemType.DataItem) return; 

     SetDataItem(e); 
    } 
+0

我一直在試圖做到這一點,但與ObjectDataSource纏繞ViewState。我沒有保存的SQL數據庫,我不想保存,直到用戶點擊「提交」。 – 2010-01-08 16:18:28

+0

你可以在代碼背後綁定一個集合 – 2010-01-08 16:55:22