gridview中的CommandName

编程入门 行业动态 更新时间:2024-10-28 04:18:06
本文介绍了gridview中的CommandName的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

大家好吧 i有一个网格视图,我就像下面的ButtonField一样 < asp:ButtonField ButtonType = 按钮 CommandName = AddToBasket 文字 = 添加到购物篮 / >

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

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

任何帮助,请 谢谢

解决方案

参考下面的链接,你可以找出出了什么问题。 ButtonField.CommandName Property [ ^ ] 如何:响应GridView控件中的按钮事件 [ ^ ] asp按钮示例:如何使用OnCommand和CommandName属性 [ ^ ]

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

在gridview中添加一个rowcommand事件,如下所示: < 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 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

本文发布于:2023-11-09 09:07:51,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1571985.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:gridview   CommandName

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!