Put multiple rows of a gridview into edit mode

后端 未结 3 1558
醉梦人生
醉梦人生 2020-12-17 05:25

I have the need to allow a user to \"tab through\" making edits on a gridview. There will be one editable column in the row data. The user should be able to hit tab and go

相关标签:
3条回答
  • 2020-12-17 05:59

    I did a workaround by creating a property in the page:

    protected bool IsEditMode
    {
      get { return this.EditMode; }
      set { this.EditMode = value; }
    }
    

    Then in the GridView I have the controls for view and edit mode inside an item template. Setting the visibility based on the property value:

    <asp:TemplateField SortExpression="Status" HeaderText="Status">
    <ItemTemplate>
        <asp:Label Id="lblStatus" Text='<%# Eval("Status") %>' Visible='<%# !IsEditMode %>' runat="server" />
        <asp:TextBox ID="txtStatus" Text='<%# Eval("Status") %>' Visible='<%# IsEditMode %>' runat="server" />
    </ItemTemplate>
    

    This works for editing the whole gridview. You'll probably need to make a few modifications to make it work for individual rows.

    0 讨论(0)
  • 2020-12-17 06:01

    Another point is how to save the results to the DataBase. While in regular use, we simple call the update command who does the work, in ItemTemplate there are now update button. So i add a button outside the GridView and in the handler i call the UpdateRow method manually for each row.

    0 讨论(0)
  • 2020-12-17 06:10

    I don't believe it is possible for a GridView to have multiple rows in edit mode simultaneously. If you want to edit multiple rows, you will need to roll your own mechanism to do so.

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