当我单击datagridview中的按钮时,可以帮助我处理事件 [英] help me handles event when i click on button in datagridview

查看:54
本文介绍了当我单击datagridview中的按钮时,可以帮助我处理事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!
我有一个问题是..当我在datagridview中单击按钮时,我不知道处理事件,我像下面的图片一样设计表单

http://nj4.upanh.com/b5 .s25.d1/1b608c451153dc01b7dd697ba98e7643_41785524.nhchupmanhinh20120308145028.png [ ^ ]

我想当我点击按钮时,它会显示该行的信息.请尽快回复我或通过电子邮件发送给我:[已删除]

Hi all!
i have a problem is.. i dont know handles event when i clicking on button in datagridview, i design my form like below picture

http://nj4.upanh.com/b5.s25.d1/1b608c451153dc01b7dd697ba98e7643_41785524.nhchupmanhinh20120308145028.png[^]

i want when i clicked on the button then it show the infor of that row. Please reply me soon or mail me with Email: [removed]

推荐答案

请查看您的屏幕.

为什么要在每一行上都想要一个按钮,该按钮执行的功能完全相同,但是数据却不同呢?
所有按钮所做的就是浪费屏幕空间,并使其显得笨拙.

为什么不只显示当前所选行的数据?这样,用户根本无需单击按钮-所选行更改时,信息将自动更新.
或者,如果要弹出一个对话框以显示数据,请考虑使用一个按钮来显示所选行的数据?再次,它减少了屏幕的占用空间,并且看起来不太忙".用户操作起来也非常简单-按钮始终位于同一位置,而不是与行一起移动.
Please, look at your screen.

Why the heck do you want a button on each and every row which does exactly the same thing, but for a different row of data?
All the buttons are doing is wasting screen real-estate and making it look clumsy.

Why not just show the data for the currently selected row? That way the user doesn''t have to click on a button at all - when the selected row changes, the information is automatically updated.
Or, if you are bringing up a dialog to show the data, consider a single button which shows the data for the selected row? Again, it reduces the screen footprint, and looks less "busy". It''s also pretty simple for the user to work out - the button is always in the same place, rather than moving with the row.


如果您使用的是TemplateField对象,并且若要访问事件处理程序方法中的行索引,请将按钮的CommandArgument属性设置为标识当前行的表达式.示例代码为:

If you are using the TemplateField object and have to access the row index in the event handler method, set the button''s CommandArgument property to an expression that identifies the current row. Sample code is:

<asp:TemplateField>
  <ItemTemplate>
    <asp:Button ID="AddButton" runat="server"

      CommandName="AddToData"

      CommandArgument="<%# ((GridViewRow) Container).RowIndex %>"

      Text="Add to Cart" />
  </ItemTemplate>
</asp:TemplateField>



为GridView控件的RowCommand事件创建一个方法,如下所示:



Create a method for the RowCommand event of the GridView control as:

protected void GridView1_RowCommand(object sender,
  GridViewCommandEventArgs e)
{
  if (e.CommandName == "AddToData")
  {
    // Add code here to related to the row.
  }

  }


好吧,我使用vb.net而不是c#:d我在datagridview上测试了hanldes事件:d
Ok i using vb.net not c# :d i testing hanldes event on datagridview :d


这篇关于当我单击datagridview中的按钮时,可以帮助我处理事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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