简体   繁体   English

获取行删除索引(devexpress ASPxGridView)

[英]Get index on row deleting (devexpress ASPxGridView )

Today I try to get the current index when clicking on a CommandColumnCustomButton button delete. 今天,当我单击CommandColumnCustomButton按钮删除时,我尝试获取当前索引。 I have a GridView populated with some values at runtime, and here is how I do to add "delete" button for each row of this control : 我有一个GridView在运行时填充一些值,这是我为该控件的每一行添加“删除”按钮的方法:

GridViewCommandColumn cmdCol = new GridViewCommandColumn();
cmdCol.Caption = "Edition";
GridViewCommandColumnCustomButton cDelBtn = new GridViewCommandColumnCustomButton();

cDelBtn.ID = "supprimer";
cDelBtn.Text = "supprimer";

cDelBtn.Visibility = GridViewCustomButtonVisibility.AllDataRows;           

cmdCol.CustomButtons.Add(cDelBtn);
gridView_test.Columns.Add(cmdCol);

It simply create a column with at each row a button which allows to delete the row. 它只是在每一行上创建一个列,该按钮允许删除该行。

Right after the last line of the code above, I added a line which precise to do something at click on those "delete" button. 在上面代码的最后一行之后,我添加了一行,只需单击那些“删除”按钮即可精确地执行操作。 Here is the code to do so : 这是这样做的代码:

gridView_test.ClientSideEvents.CustomButtonClick = "function (s, e) { alert( e.FocusedRowIndex ); }";

The function takes two argument (like the event handler basic function in ASP) : s is the "sender", which represent the object (there, it is the "delete" button), and e is the "event". 该函数有两个参数(类似于ASP中的事件处理程序基本函数):s是“发送者”,代表对象(在那里,它是“删除”按钮),e是“事件”。 I tried so to catch the current index of the event but it doesn't works, displaying me "undefined". 我试图捕获事件的当前索引,但它不起作用,向我显示“未定义”。

Please see below an example of the working process I would like to implement : 请在下面查看我要实现的工作流程的示例:

PRICE  |   Edit
  5    |  delete
  18   |  delete

I would like, when clicking on the "delete" button from the second line, to display "1", which is the index of the array which represent the GridView (because as you know arrays begin from index 0...). 我想在第二行单击“删除”按钮时显示“ 1”,它是表示GridView的数组的索引(因为您知道数组从索引0开始...)。

Some knows how can I could do this in the javascript part of my function right below ? 有些人知道如何在下面的函数的javascript部分中做到这一点? Or maybe an alternative exists ? 也许存在替代方案?

Further Informations : DevExpress version : 14.1 Control : ASPxGridView IDE : Visual Studio 2013 Langage : ASP.net WebForms 更多信息:DevExpress版本:14.1控件:ASPxGridView IDE:Visual Studio 2013语言:ASP.net WebForms

Found my error, it was not the proper proprety I used. 发现我的错误,这不是我使用的正确财产。 Better use "visibleIndex" attribute : 最好使用“ visibleIndex”属性:

e.visibleIndex

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM