如何手动创建GridView编辑按钮并为其编写代码? [英] How to create a GridView edit button manually and write code for it?

查看:118
本文介绍了如何手动创建GridView编辑按钮并为其编写代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

您能给我打电话,如何为每行手动创建一个GridView编辑按钮并为其编写代码(在单击事件中)?

预先谢谢您...

Hi there,

Can you tel me, how to create a GridView edit button for each row manually and write code for it (in its click event)?

Thank you in advance...

推荐答案

在您的gridview列中添加此代码.
在您的gridview中添加模板字段.

Add this code in you gridview columns.
Add template field in your gridview.

<asp:TemplateField >
                                       <ItemTemplate>
                                           <asp:Button id="btnEdit" runat="server" Text="Edit" CommandName="Edit" CssClass="btn" CausesValidation="false"/>
                                       </ItemTemplate>
                                   </asp:TemplateField>
                                   <asp:TemplateField >




----------------------------
在Codebehind中




----------------------------
In Codebehind

protected void gv_RowEditing(object sender, GridViewEditEventArgs e)
  {
      Int32 iID = Convert.ToInt32((gv.DataKeys[e.NewEditIndex].Value));
      EditMethod(iID)         // now you can send ID and retrieve data.
  }



请将此代码写在后面的代码中.

您可以获得编辑元素的ID.这可以获取特定行的数据.
这是最终解决方案.



Please write this code in code behind.

You can get Id of editing element. This can fetch data of specific row.
This is final solution.


我不太确定你要干什么.
DataGridView的属性中,可以设置它的EditMode.
I''m not quite sure what it is you''re after.
In the Properties of the DataGridView you can set it''s EditMode.


这篇关于如何手动创建GridView编辑按钮并为其编写代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆