【问题标题】:How to make one row editable in gridview asp.net如何在gridview asp.net中使一行可编辑
【发布时间】:2019-09-08 06:20:24
【问题描述】:

我正在使用 asp.net 网格视图。我不想添加切换到编辑模式的按钮。我只想在 page_load 上的 gridview 中使一列可编辑。

我在 产品数量的第二列上有一个 asp.net 文本框,我想更改值

默认打开 <ItemTemplate> 并且不可编辑。

我的 Gridview 列:

Product Name, Quantity, Price

【问题讨论】:

    标签: c# asp.net gridview aspxgridview


    【解决方案1】:

    您可以使用中继器而不是 GridView。

    只需在 aspx 页面中构建表格,用作不可编辑列的文字控件和可编辑的文本框。

    <ItemTemplate>
       <tr>
          <td style="text-align: center">
             <asp:Literal ID="Literal1" runat="server" Text='<%# Eval("ProductName") %>' />  
          </td>
          <td>
              <asp:TextBox runat="server" ID="txtPrice" Text='<%# Eval("Price") %>'></asp:TextBox>
          </td>
       </tr>
    </ItemTemplate>
    

    我使用放置在表格列中的 ImageButton,单击该按钮会将记录保存到数据库。

    <asp:ImageButton ID="ibtnEdit" ImageUrl="/images/save.jpg" CommandArgument='<%#"Edit_" + Eval("ProductID") %>' runat="server" ImageAlign="Middle" ClientIDMode="AutoID" CausesValidation="False" />
    

    对我来说效果很好。 希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多