szpzr
发表于 2018-4-27 12:36:40
好的,谢谢!
dexteryao
发表于 2018-4-27 14:09:24
{:4_86:}
dexteryao
发表于 2018-5-7 15:54:49
请参考
public class MyItemTemplate : FarPoint.Web.Spread.MenuItem, ITemplate
{
public MyItemTemplate(string text, string commandName, string commandArgument): base(text, commandName, commandArgument){}
public void InstantiateIn(Control container)
{
if (container != null)
{
//Add a custom control as item
CheckBox check1 = new CheckBox();
check1.ID = base.CommandName;
check1.Text = base.Text;
if (base.OnClientClick != null)
check1.Attributes.Add("onclick", OnClientClick);
container.Controls.Add(check1);
}
}
}
protected void Page_Load(object sender, EventArgs e)
{
FpSpread1.MenuItemClicked += new FarPoint.Web.Spread.MenuItemClickedHandler(FpSpread1_MenuItemClicked);
if (this.IsPostBack) return;
FpSpread1.EnableContextMenu = true;
BuildMenu();
}
protected void FpSpread1_MenuItemClicked(object sender, FarPoint.Web.Spread.MenuItemClickEventArgs eventArgs)
{
FpSpread1.Sheets.Cells.Text = eventArgs.SelectedItem.CommandName.ToString();
FpSpread1.Sheets.Cells.Text = eventArgs.SelectedItem.CommandArgument.ToString();
BuildMenu();
}
private void BuildMenu()
{
FpSpread1.ContextMenus.Clear();
FarPoint.Web.Spread.ContextMenu viewportMenu = new FarPoint.Web.Spread.ContextMenu();
viewportMenu.Type = FarPoint.Web.Spread.ContextMenuType.Viewport;
string itemText = string.Empty;
string itemCmdName = string.Empty;
string itemCmdArg = string.Empty;
for (int i = 0; i < 3; i++)
{
itemText = string.Format("Menu item {0}", i + 1);
itemCmdName = string.Format("cmd{0}", i + 1);
itemCmdArg = string.Format("arg{0}", i + 1);
FarPoint.Web.Spread.MenuItem item = new FarPoint.Web.Spread.MenuItem(itemText, itemCmdName, itemCmdArg);
if (i == 1)
{
MyItemTemplate myItem = new MyItemTemplate(itemText, itemCmdName, itemCmdArg);
myItem.OnClientClick = string.Format("javascript:alert('cmd = {0}, checked = ' + this.checked); return;", itemCmdName);
item.ItemTemplate = myItem;
}
else if (i == 2)
{
for (int j = 0; j < 3; j++)
{
itemText = string.Format("Menu item {0}.{1}", i + 1, j + 1);
itemCmdName = string.Format("cmd{0}${1}", i + 1, j + 1);
itemCmdArg = string.Format("arg{0}${1}", i + 1, j + 1);
FarPoint.Web.Spread.MenuItem newItem = new FarPoint.Web.Spread.MenuItem(itemText, itemCmdName, itemCmdArg);
if (j == 0)
{
MyItemTemplate myItem = new MyItemTemplate(itemText, itemCmdName, itemCmdArg);
myItem.OnClientClick = string.Format("javascript:alert('cmd = {0}, checked = ' + this.checked); return;", itemCmdName);
newItem.ItemTemplate = myItem;
}
item.ChildItems.Add(newItem);
}
}
viewportMenu.Items.Add(item);
}
FpSpread1.ContextMenus.Add(viewportMenu);
}
szpzr
发表于 2018-5-7 17:25:24
谢谢!姚工,辛苦您了。
dexteryao
发表于 2018-5-7 17:27:26
您根据您的需求调整下,有问题再发帖
szpzr
发表于 2018-5-8 07:48:38
本帖最后由 szpzr 于 2018-5-8 08:04 编辑
姚工:myItem.OnClientClick = string.Format("javascript:alert('cmd = {0}, checked = ' + this.checked); return;", itemCmdName);定义了客户端事件,能否激发服务器端的事件?还有:myItem = new MyItemTemplate(itemText, itemCmdName, itemCmdArg);能否根据列是否显示设定checkbox勾选或不勾选?
dexteryao
发表于 2018-5-8 09:42:53
给MyItemTemplate 一个IsChecked的属性,初始化时候设置上。
MyItemTemplate myItem = new MyItemTemplate(itemText, itemCmdName, itemCmdArg);
myItem.IsChecked = true;
public bool IsChecked { get; set; }
check1.Checked = this.IsChecked;
触发服务端事件,您可以在前端post回去一个指令,加一些参数就可以了,
就和页面放一个button,点了一下隐藏了一列一样。直接checkbox挂服务端事件反而麻烦。
szpzr
发表于 2018-5-8 10:49:38
菜单已生成了,我想在“确定”勾选框为true时,
触发服务端事件,在前端post回去一个指令,加一些参数就可以了,如何做?不好意思,麻烦您了,姚工。
dexteryao
发表于 2018-5-8 15:05:17
szpzr 发表于 2018-5-8 10:49
菜单已生成了,我想在“确定”勾选框为true时,
触发服务端事件,在前端post回去一个指令,加一些参数就可 ...
这个已经和产品没有关系了,您查询下如何js post数据到服务端更新很多文章的。
把您点击的这个checkbox对应的列号post回去,设置下列隐藏,更新即可。
szpzr
发表于 2018-5-9 15:46:06
姚工,不好意思,页面刷新后,生成的菜单没有勾选框,跟spread分组没关系吧?