How do I edit all rows in an ASP.NET ListView control at the same time?

后端 未结 1 515
余生分开走
余生分开走 2021-01-06 18:36

I would like to know how to put all of my ListView rows into edit mode at once. I am not looking for the traditional behavior of editing each row one at a time. The answer

1条回答
  •  [愿得一人]
    2021-01-06 19:03

    Probably the easiest way is to just use the ListView's ItemTemplate, so in essence, the ListView is always in "edit mode":

    
    
        
            
                
                    <%# Eval("department_id") %>
                
                
                    
                
            
        
        
            

    No departments found.

    Department ID Name

    You can then read the changed values when the user clicks the button:

    protected void cmdSave_Click ( object sender, EventArgs e )
    {
        foreach ( ListViewItem item in lvwDepartments.Items )
        {
            if ( item.ItemType == ListViewItemType.DataItem )
            {
                TextBox txtDepartmentName = ( TextBox ) item.FindControl( "txtDepartmentName" );
    
                // Process changed data here...
            }
        }
    }
    

    0 讨论(0)
提交回复
热议问题