单击gridview中的特定按钮时执行事件

编程入门 行业动态 更新时间:2024-10-08 20:37:35
本文介绍了单击gridview中的特定按钮时执行事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

嗨 我在gridview单元格中有一个按钮列表,现在我需要每个按钮在单击时执行不同的事件.我该如何解决? 我试图将其放在Page_Load上,但不起作用

Hi I have a list of buttons inside my gridview cells, now i need each button to execute a difrent event when its clicked. how can i solve this? I tried to put this on Page_Load but not working

foreach (GridViewRow rowItem in GridView1.Rows) { Button btnMonday = (Button)(GridView1.Rows[0].Cells[1].FindControl("btnMonday")); btnMonday.Click += new EventHandler(this.mondae_Click); Button btnTuesday = (Button)(GridView1.Rows[0].Cells[2].FindControl("btnMonday")); btnTuesday.Click += new EventHandler(this.mondae_Click); }

What should i do or where should i put it??

推荐答案

如何:在GridView控件中响应按钮事件 [ ^ ]

foreach (GridViewRow rowItem in GridView1.Rows) { // why are you never using the ''rowItem variable ? Button btnMonday = (Button)(GridView1.Rows[0].Cells[1].FindControl("btnMonday")); btnMonday.Click += new EventHandler(this.mondae_Click); // why is the Button in Cell[2] named ''btnMonday'' ? Button btnTuesday = (Button)(GridView1.Rows[0].Cells[2].FindControl("btnMonday")); btnTuesday.Click += new EventHandler(this.mondae_Click); }

因为您没有在循环中使用''rowItem变量,所以您的代码现在在Row [0]中设置相同的两个按钮,以具有同一事件处理程序的多个副本.

Because you do not use the ''rowItem variable in the loop, your code is now setting the same two buttons in Row[0] to have multiple copies of the same Event handler.

命令名称中的每个按钮添加不同的值 &在设计中,使所有按钮的单击事件按钮都是同一事件 然后在发生事件的情况下,单击尝试此代码 开关((((button)sender)mandname) { 重视您的价值 执行代码 休息; 列出您的其他值 执行代码 休息; } for each button in the command name add different value & in the design make the click event button for the all buttons is the same event then in the event click try this code switch (((button)sender)mandname) { case your value execute code break; case your other value execute code break; }

更多推荐

单击gridview中的特定按钮时执行事件

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

发布评论

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

>www.elefans.com

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