gridview中的CommandName [英] CommandName in gridview

查看:81
本文介绍了gridview中的CommandName的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好吧



i有一个网格视图,我就像下面的ButtonField一样



< pre lang =HTML> < asp:ButtonField ButtonType = 按钮 CommandName = AddToBasket 文字 = 添加到购物篮 / >





我点击它时,没有事件发生,但我做了一个同名的功能



  public   bool  AddToBasket( string  cart_id,字符串 item_id,字符串价格,字符串数量)





任何帮助,请



谢谢

解决方案

参考下面的链接,你可以找出出了什么问题。



ButtonField.CommandName Property [ ^ ]



如何:响应GridView控件中的按钮事件 [< a href =http://msdn.microsoft.com/en-us/library/bb907626(v=vs.100).a spxtarget =_ blanktitle =New Window> ^ ]



asp.net按钮示例:如何使用OnCommand和CommandName属性 [ ^ ]


 < span class =code-keyword> 没有事件处理程序 asp:ButtonField标记,写入事件处理程序用于命令单击并在中指定 关键字>事件处理程序


在gridview中添加一个rowcommand事件,如下所示:



<前lang =HTML > < asp:GridView ID = GridView1 runat = 服务器 AutoGenerateColumns = False

onrowcommand = GridView1_RowCommand CellPadding = 4 ForeColor = #333333 GridLines = >





在代码隐藏中处理它;

  protected   void  GridView1_RowCommand( object  sender, GridViewCommandEventArgs e)
{
// 你的功能
}


hi all

i have a grid view and i made ButtonField on it like below

<asp:ButtonField ButtonType="Button" CommandName="AddToBasket" Text="Add to Basket" />



while i clicked on it , no event occurs , however i made a function with the same name

public bool AddToBasket(string cart_id, string item_id, string price, string quantity)



any help, please

thanks

解决方案

Refer to below links and you can figureout what went wrong.

ButtonField.CommandName Property[^]

How to: Respond to Button Events in a GridView Control[^]

asp.net Button example: how to use OnCommand and CommandName property[^]


there is no event handler written in asp:ButtonField tag, write eventhandler for the commandclick and assign ur c sharp method  in that event handler


Add a rowcommand event in your gridview like this:

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"

onrowcommand="GridView1_RowCommand" CellPadding="4" ForeColor="#333333"GridLines="None">



Handle it in codebehind as;

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
//you functionality
}


这篇关于gridview中的CommandName的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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