We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Validation DropdownList with Context menu

Hello,

My requirement is adding dropdown in the WebGrid cell. I have achieved this by using validation, but after using validaion I have lost a control on context menu (CustomCommand button). Context menu has displayed but Server Side acWGTemplateField_CustomCommand event does not fired. Can you please help me out to solve this issue? Is it possible to fire a server side event like SelectionIndexChanged or SelectionValueChanged events for dropdown?

I am using Licence Version 2.7.8.2000

///Client Side Script

<script type="text/javascript" language="javascript">

function ShowAttributeForm(column, row) {

alert("column : " + (column+1) + " row : " + (row+1));

}

function onContextMenuShow() {

var menu = event.srcElement;

//menu.setItemVisibility("Delete", "block");

// menu.setItemVisibility("Update", "none");

//callServerEvent();

}

function callServerEvent() {

__doPostBack("acWGTemplateField", "acWGTemplateField_CustomCommand");

}

function onCellSelected(cell) {

//var cell = acWGTemplateField.getActiveCell();

//alert("Cell row:" + igWGBTemplateField_acWGTemplateField.getActiveRow() + " Cell column: " + igWGBTemplateField_acWGTemplateField.getActiveColumn());

if (document.getElementById("hdnActiveRow")) {

document.getElementById("hdnActiveRow").value = acWGTemplateField.getActiveRow();

}

if (document.getElementById("hdnActiveColumn")) {

document.getElementById("hdnActiveColumn").value = acWGTemplateField.getActiveColumn();

}

}

function DoubleClickCellClientFunction(sender, args) {

alert("Double Click Event :: Row : " + (acWGTemplateField.getActiveRow()+1) + " Column : " + (acWGTemplateField.getActiveColumn()+1));

}

function CellUpdatedClientFunction(sender, args) {

alert("Cell Focus Lost Event :: Row : " + (acWGTemplateField.getActiveRow()+1) + " - Column : " + (acWGTemplateField.getActiveColumn()+1) + " - Column Name : " + sender.childNodes[0].outerText);

}

</script>

///Aspx page code

<table id="tblMain" cellpadding="0" cellspacing="0" border="0" class="MainTable"><tr><td><table><tr><td> <acw:GridWeb ID="acWGTemplateField" runat="server" Width="100%" Height="658px" ShowLoading="false" ShowContextMenu="true" EditMode="true" OnCustomCommand="acWGTemplateField_CustomCommand" ShowBottomBar="False" OnCellUpdatedClientFunction="CellUpdatedClientFunction" EnableDoubleClickEvent="True" OnDoubleClickCellClientFunction="DoubleClickCellClientFunction" XhtmlMode="True" ShowSaveButton="False" OnContextMenuShowClientFunction="onContextMenuShow" ShowSubmitButton="False" ShowUndoButton="False" OnCellSelectedClientFunction="onCellSelected" >

<CustomCommandButtons> <acw:CustomCommandButton Command="InsertColumn" Text="Insert Column" CommandType="ContextMenuItem"></acw:CustomCommandButton>

<acw:CustomCommandButton Command="DeleteColumn" Text="Delete Column" CommandType="ContextMenuItem"></acw:CustomCommandButton>

<acw:CustomCommandButton Command="InsertRow" Text="Insert Row" CommandType="ContextMenuItem"></acw:CustomCommandButton>

<acw:CustomCommandButton Command="DeleteRow" Text="Delete Row" CommandType="ContextMenuItem"></acw:CustomCommandButton>

</CustomCommandButtons>

</acw:GridWeb></td></tr></table>

<asp:HiddenField ID="hdnActionMode" runat="server" ClientIDMode="Static" /><asp:HiddenField ID="hdnActiveRow" runat="server" ClientIDMode="Static" Value="0" /><asp:HiddenField ID="hdnActiveColumn" runat="server" ClientIDMode="Static" Value="0" /></td></tr></table>

///Server side code

protected void Page_Load(object sender, EventArgs e)

{

Aspose.Cells.GridWeb.License license = new Aspose.Cells.GridWeb.License();

license.SetLicense("Aspose.Cells.lic");

if (!IsPostBack)

{

LoadTemplateFieldData();

//acWGTemplateField.EditMode = false;

}

}

private void LoadTemplateFieldData()

{

acWGTemplateField.WebWorksheets.Clear();

acWGTemplateField.WebWorksheets.Add("Sample Aspose");

#region Sample

WebWorksheet sheet = acWGTemplateField.WebWorksheets[0];

Aspose.Cells.GridWeb.TableItemStyle style = new Aspose.Cells.GridWeb.TableItemStyle();

sheet.Cells[1, 0].PutValue("Jack");

sheet.Cells[1, 1].PutValue("M");

sheet.Cells[1, 2].PutValue(19);

sheet.Cells[1, 3].PutValue("One");

sheet.Cells[2, 0].PutValue("Tome");

sheet.Cells[2, 1].PutValue("M");

sheet.Cells[2, 2].PutValue(20);

sheet.Cells[2, 3].PutValue("Four");

sheet.Cells[3, 0].PutValue("Jeney");

sheet.Cells[3, 1].PutValue("W");

sheet.Cells[3, 2].PutValue(18);

sheet.Cells[3, 3].PutValue("Two");

sheet.Cells[4, 0].PutValue("Marry");

sheet.Cells[4, 1].PutValue("W");

sheet.Cells[4, 2].PutValue(17);

sheet.Cells[4, 3].PutValue("There");

sheet.Cells[5, 0].PutValue("Amy");

sheet.Cells[5, 1].PutValue("W");

sheet.Cells[5, 2].PutValue(16);

sheet.Cells[5, 3].PutValue("Four");

sheet.Cells[6, 0].PutValue("Ben");

sheet.Cells[6, 1].PutValue("M");

sheet.Cells[6, 2].PutValue(17);

sheet.Cells[6, 3].PutValue("Four");

// DropDownList.

CreateDropDown(sheet.Cells[1, 0]);

CreateDropDown(sheet.Cells[1, 1]);

CreateDropDown(sheet.Cells[1, 2]);

CreateDropDown(sheet.Cells[1, 3]);

CreateDropDown(sheet.Cells[2, 0]);

CreateDropDown(sheet.Cells[2, 1]);

CreateDropDown(sheet.Cells[2, 2]);

CreateDropDown(sheet.Cells[2, 3]);

this.acWGTemplateField.EnableDoubleClickEvent = true;

acWGTemplateField.ShowBottomBar = false;

#endregion

}

private void CreateDropDown(WebCell cell)

{

cell.CreateValidation(Aspose.Cells.GridWeb.ValidationType.DropDownList, true);

cell.Validation.ValueList.Add("Bachelor");

cell.Validation.ValueList.Add("Master");

cell.Validation.ValueList.Add("Doctor");

}

protected void acWGTemplateField_CustomCommand(object sender, string command)

{

int column = (((Aspose.Cells.GridWeb.GridWeb)(sender)).ActiveCell).Column;

int Row = (((Aspose.Cells.GridWeb.GridWeb)(sender)).ActiveCell).Row;

switch (command)

{

case "InsertColumn":

acWGTemplateField.WebWorksheets[0].Cells.InsertColumn(column);

break;

case "DeleteColumn":

acWGTemplateField.WebWorksheets[0].Cells.DeleteColumn(column);

break;

case "InsertRow":

acWGTemplateField.WebWorksheets[0].Cells.InsertRow(Row);

break;

case "DeleteRow":

acWGTemplateField.WebWorksheets[0].Cells.DeleteRow(Row);

break;

}

acWGTemplateField.EditMode = true;

}

Appriciate quick reply

Regards,

Nilesh Dhote

Hi,

Thanks for your sample code and using Aspose.Cells for GridWeb

Please download and use the latest version:
Aspose.Cells
for GridWeb v2.7.9.2000
and provide us your runnable sample project.

Please also provide us screenshots to further illustrate your issue.

It will help us look into your requirements better and we help you asap.

Hello,

I have added latest verion of ASPOSE.CELLS as per your reply. I have tried that in my code but still I am not able to access context menu if I have a Validation dropdown list in any cell. Please find the attached code for the reference.

Hi,

Thanks for your sample project.

I was able to notice this issue. When the following lines of code is commented


cell.CreateValidation(Aspose.Cells.GridWeb.ValidationType.DropDownList, true);
cell.Validation.ValueList.Add(“Bachelor”);
cell.Validation.ValueList.Add(“Master”);
cell.Validation.ValueList.Add(“Doctor”);


Context Menu fires the server side event, but when they were uncommented, Context Menu does not fire any server side event.

We have logged this issue in our database. We will look into it and fix the issue. Once the problem is resolved or we have some other update for you, we will let you know asap.

This issue has been logged as CELLSNET-40991.

Hi,

We have tested your sample project and there are three points which you should pay attention:

1. You have added validation by using CreateDropDown method, when it executes some client method such as “insert column”, the client script will validate all the cells [1,0][1,1][1,2] etc . for example [1,1], the data is “M” , it is not existed in [“Bachelor”,”Master”,”Doctor”], so the client script will not execute the command “insert column”, only after the client fixes the validation, the client script will submit “insert column” command to the server side.

private void CreateDropDown(WebCell cell)
{

cell.CreateValidation(ValidationType.DropDownList, false);

cell.Validation.ValueList.Add(“Bachelor”);

cell.Validation.ValueList.Add(“Master”);

cell.Validation.ValueList.Add(“Doctor”);

///cell.Validation.ClientValidationFunction = “SetDropDownValue”;
}


2. If you want to call “insert column” etc. without dropdown validation, you should set property acWGTemplateField.ForceValidation = false;

3. You cannot use the customcommand with the text ”Insert Column”, ”Delete Column”, “Delete Column”, “Insert Row”, “Delete Row”, since that if you will use it, it will call the gridweb’s default “InsertColumn”, “DeleteColumn”, ”InsertRow”, “DeleteRow” commands and it will not call customcommand .