How to enable in-place editing in asp: gridview?

How can I add edit fields and read their values ​​while sending with asp:Repeater?


i has asp:GridView, which displays a read-only dataset (i.e. not editable), for example:

enter image description here

How can I activate cells GridViewfor editing, for example (Photoshop Mockup):

enter image description here

Note. I did not mock up the edit box in each row and column in Photoshop (because it is too long). You still understand.

  • How can I convince you to asp:GridViewshow the editing window in each cell?
  • If I urge to asp:GridViewshow the editing window, how can I “read” their SaveOnClick buttons ?

Bonus Chat

i will not mind using asp:Repeatermanually placing controls <INPUT>. My confusion is how to read each entry during the SaveOnClick button . And although I would be happy to use a repeater, and the GridView might not be able to accomplish what I want to make the repeater the only option, this question is about the GridView.

  • If the GridView can do this: excellent; as?
  • If the GridView cannot do this: this is also the answer.
+5
source share
2 answers

Have you tried setting the property EditIndexin DataGrid?

Example:

<asp:GridView runat="server" onrowediting="grdProducts_RowEditing" 
    ID="grdProducts">
    <Columns>
        <asp:CommandField ShowEditButton="True" />
    </Columns>
</asp:GridView>

Code for

    protected void grdProducts_RowEditing(object sender, GridViewEditEventArgs e)
    {
        this.grdProducts.EditIndex = e.NewEditIndex;
        This.BindGrid();
    }

Note that you must re-snap your grid

, , , , , ,

GridView:

    protected void grdProducts_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        // old values for the current row
        var oldValues = e.OldValues;

        // new (updated) values for the current row
        var newvalues = e.NewValues;

        // Exit edit mode
        this.grdProducts.EditIndex = -1;

        // Update the grid
        this.BindGrid();
    }

:

    onrowupdating="grdProducts_RowUpdating"

, :

       <Columns>
        <asp:TemplateField HeaderText="Name">
            <EditItemTemplate>
                <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Name") %>'></asp:TextBox>
            </EditItemTemplate>
            <ItemTemplate>
                <asp:Label ID="Label1" runat="server" Text='<%# Bind("Name") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
      </Columns>
+8

GridView, , .

GridView. . :

<asp:GridView ID="test" runat="server" AutoGenerateColumns="false">
    <Columns>
        <asp:TemplateField HeaderText="Foo" SortExpression="foo">
            <ItemTemplate>
                <asp:TextBox ID="FooText" runat="server" Text='<%# Eval("Foo") %>'></asp:TextBox>
            </ItemTemplate>
        </asp:TemplateField>
        <!-- other cols here -->
    </Columns>
</asp:GridView>
<asp:Button ID="Save" runat="server" Text="Save" OnClick="Save_Click" />

"" GridView:

foreach (GridViewRow gvRow in test.Rows)
{
    string val = ((TextBox)gvRow.FindControl("FooText")).Text;
    <!-- other cols here -->
    //do something with all the values you have parsed from the row
}
+3

All Articles