DevExpress中PopupMenu的小成果
哎。。。由于本人小菜,英语水平不高,官方文档看了半天才找到关于PopupMenu中的抓取Grid中RowIndex值。不多说,直接上代码,记录自己的学习成果。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>SimpleGrid</title> <script type="text/javascript"> function ContextMenu(s, e) { //只有在数据行显示PopupMenu if (e.objectType == 'row') { //清除本页已经选择的行 s.UnselectAllRowsOnPage(); var rowIndex = e.index; //设置右键处的行为选中 s.SetFocusedRowIndex(rowIndex); //弹出菜单 popupMenu.ShowAtPos(ASPxClientUtils.GetEventX(e.htmlEvent), ASPxClientUtils.GetEventY(e.htmlEvent)); } } </script> </head> <body> <form id="form1" runat="server"> <div> <br /> <br /> <br /> </div> <div> <dx:ASPxGridView ID="grid" ClientInstanceName="grid" runat="server" Width="95%" KeyFieldName="Time"> <SettingsBehavior AllowSelectByRowClick="true" AllowSelectSingleRowOnly="true" AllowFocusedRow="true" /> <ClientSideEvents ContextMenu="ContextMenu" /> </dx:ASPxGridView> <dx:ASPxPopupMenu ID="popupMenu" runat="server" AutoPostBack="true" OnItemClick="popupMenu_ItemClick"> <Items> <dx:MenuItem Text="新增" Name="Add"> </dx:MenuItem> <dx:MenuItem Text="编辑" Name="Edit"> </dx:MenuItem> <dx:MenuItem Text="删除" Name="Delete"> </dx:MenuItem> <dx:MenuItem Text="刷新" Name="Refresh"> </dx:MenuItem> </Items> </dx:ASPxPopupMenu> <dx:ASPxLabel ID="lblResult" runat="server" Text="ASPxLabel"> </dx:ASPxLabel> </div> </form> </body> </html>
后台菜单绑定获取值的代码如下:
protected void popupMenu_ItemClick(object sender, DevExpress.Web.ASPxMenu.MenuItemEventArgs e) { if (e.Item != null) { switch (e.Item.Name) { case "Add": lblResult.Text = "Add" + grid.FocusedRowIndex; break; case "Edit": lblResult.Text = "Edit" + grid.FocusedRowIndex; break; case "Delete": lblResult.Text = "Delete" + grid.FocusedRowIndex; break; case "Refresh": lblResult.Text = "Refresh" + grid.FocusedRowIndex; break; } } }
作 者:D.J. Chan 出 处:http://www.cnblogs.com/djchan/ 欢迎任何形式的转载,但请务必注明出处。 |