简体   繁体   中英

Is it possible to edit a GridView cell without an edititemtemplate?

<asp:GridView ID="GridView1" runat="server">
    <Columns>
        <asp:TemplateField>
            <ItemTemplate>
                <asp:LinkButton ID="LinkButton1" runat="server" OnClick="lclick">Buy</asp:LinkButton>
            </ItemTemplate>
    <edititemtemplate>
        <asp:Textbox runat="server" id="txt"/>
    <edititemtemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>

Is it possible to edit the GridView without the edititem Template?

I have done this before and I can only explain what I did

To make sure my edit controls is part of viewstate I added an empty form to the bottom of my page

<div id="myeditform">
   <table>
   <tr>
     <td><asp:HiddenField runat="server" ID="myRowId" />
     </td>

     <td>... other controls </td>

     <td>... Save button -- </td>
   </tr>
   <table>
</div>

The tr(s) has to match the number of columns in your grid or you can use colspan

Then

  • use jQuery or javascript to get the row (eg the nearest parent to the edit link clicked),
  • get the td(s) and pass the value of each td to the respective control in your edit form.
  • replace your <tr> with the content of the table in your edit form
  • when save is clicked, refresh the page to update gridview

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM