Gridview之RowCommand,ButtonField[add buttons and use the RowCommand event to add custom functionality...

本文详细介绍了ASP.NET中GridView控件的ButtonField使用方法及RowCommand事件处理过程。通过设置CommandName属性,可以触发如编辑、删除等内置功能,并提供了一个具体的事件处理示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

先查阅了MSDN官方网站关于GridView的相关ButtonField,RowCommand的内容。
http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowcommand.aspx
先摘抄些关键的东西:
Occurs when a button is clicked in a GridView control.
Namespace:  System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)
The RowCommand event is raised when a button is clicked in the GridView control. This enables you to provide an event-handling method that performsa custom routine whenever this event occurs.
Buttons within a GridView control can also invoke some of the built-in functionality of the control. To perform one of these operations, set the CommandName property of a button to one of the values in the following table.

"Cancel"

Cancels an edit operation and returns the GridView control to read-only mode. Raises the RowCancelingEdit event.

"Delete"

Deletes the current record. Raises the RowDeleting and RowDeleted events.

"Edit"

Puts the current record in edit mode. Raises the RowEditing event.

"Page"

Performs a paging operation. Sets the CommandArgument property of the button to "First", "Last", "Next", "Prev", or a page number to specify the type of paging operation to perform. Raises the PageIndexChanging and PageIndexChanged events.

"Select"

Selects the current record. Raises the SelectedIndexChanging and SelectedIndexChanged events.

"Sort"

Sorts the GridView control. Raises the Sorting and Sorted events.

"Update"

Updates the current record in the data source. Raises the RowUpdating and RowUpdated events.


之后我又查阅了MSDN walkthrough
http://msdn2.microsoft.com/en-us/library/bb907626.aspx
You can use the CommandName property of the event argument to identify the button's function in the event handler method.
protected   void  GridView1_RowCommand( object  sender, 
  GridViewCommandEventArgs e)
{
  
if (e.CommandName == "AddToCart")
  
{
    
// Retrieve the row index stored in the 
    
// CommandArgument property.
    int index = Convert.ToInt32(e.CommandArgument);

    
// Retrieve the row that contains the button 
    
// from the Rows collection.
    GridViewRow row = GridView1.Rows[index];

    
// Add code here to add the item to the shopping cart.
  }


  }


其它相关参考网址:
http://msdn2.microsoft.com/en-us/library/bb498196.aspx

转载于:https://www.cnblogs.com/onlyendure/archive/2008/04/08/1141991.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值