asp.net
  • c#-4.0
  • 2015-09-28 43 views 0 likes 
    0

    我有这样的项目,需要从列表视图中添加记录到数据库如何从列表视图中添加多个数据到数据库的SQL Server

    这是在ASPX:

    <asp:ListView ID="lvPODetails" runat="server"> 
        <ItemTemplate> 
          <tr> 
           <td> 
            <asp:Literal ID="ltRefNo" runat="server" Text='<%# Eval("PODetailNo") %>' Visible="false" /> 
             <%# Eval("ProductName")%> 
           </td> 
           <td> 
            <%# Eval("Price", "{0: #,###.00}") %> 
           </td> 
           <td><%# Eval("DesiredQuantity") %></td> 
           <td><asp:TextBox ID="txtQuantity" runat="server" type="number" Text='<%# Eval("DesiredQuantity") %>' class="form-control" /></td> 
           <td><%# Eval("POAmount", "{0: #,###.00}") %></td> 
           <td><%# Eval("POAmount", "{0: #,###.00}") %></td> 
           <td> 
    
           </td> 
          </tr> 
    
        </ItemTemplate> 
        <EmptyDataTemplate> 
         <tr> 
          <td colspan="4"><h2 class="text-center">No records found.</h2></td> 
         </tr> 
        </EmptyDataTemplate> 
    </asp:ListView>   
    

    这是CS :

    protected void btnAdd_Click(object sender, EventArgs e) 
    { int ProductQuantity; 
        string ProductName; 
    
        ProductName = Convert.ToString(lvPODetails.FindControl("ltRefNo")); 
        ProductQuantity = Convert.ToInt32(lvPODetails.FindControl("txtQuantity")); 
    } 
    

    我似乎无法找到找到ltRefNo和txtQuantity的正确方法。 或者aspx错误呢?

    +0

    这是不应该做的方式。看到这里的基本例子。 http://www.codeproject.com/Articles/44070/Insert-a-new-record-using-ListView-with-a-GridView – pedram

    +0

    我正在查看你发送的指南。这会在一次点击中添加多行吗? – gamered123

    +1

    老兄,我已经告诉过这个是基本的例子。从基本的东西开始学习任何东西。你可以玩ItemCommand Event。设置命令名称并运行你的代码。 – pedram

    回答

    1

    看到这里的示例代码,

    if(e.CommandName == "SaveAll") 
    { 
        foreach (ListViewItem item in ListViewName.Items) 
        { 
         // Code goes here. You can find control using e.Item.Findcontrol 
        } 
    } 
    
    +0

    但是,如何从listview中找到那些文本框? – gamered123

    +0

    在foreach循环中看到,尝试使用item对象查找控件。 TextBox txt =(TextBox)item.FindControl(“txtQuantity”); – pedram

    +0

    这个工作也是文字? – gamered123

    0

    使用itemcommand在列表视图

    protected void lvPODetails_ItemCommand(object sender, ListViewCommandEventArgs e) 
    { 
        if(e.CommandName) 
        { 
         var txtquentity = e.Item.FindControl("txtQuantity") as TextBox; 
    
        } 
    } 
    
    +0

    我需要在一次点击中添加多行 – gamered123

     相关问题

    • 暂无相关问题^_^