protected void btnAddDropDownListValidation_Click(object sender, EventArgs e) { // ExStart:AddDropDownListValidation // Accessing the cells collection of the worksheet that is currently active GridWorksheet sheet = GridWeb1.WorkSheets[GridWeb1.ActiveSheetIndex]; // Access "B1" cell and add some text GridCell cell = sheet.Cells[0, 1]; cell.PutValue("Select Degree:"); // Accessing "C1" cell cell = sheet.Cells[0, 2]; // Creating DropDownList validation for the "C1" cell var validation = cell.CreateValidation(GridValidationType.DropDownList, true); // Adding values to DropDownList validation var values = new System.Collections.Specialized.StringCollection(); values.Add("Bachelor"); values.Add("Master"); values.Add("Doctor"); validation.ValueList = values; // ExEnd:AddDropDownListValidation }
protected void btnAddCustomValidation_Click(object sender, EventArgs e) { // Accessing the cells collection of the worksheet that is currently active GridWorksheet sheet = GridWeb1.WorkSheets[GridWeb1.ActiveSheetIndex]; // Access cell B1 and add input message text GridCell cell = sheet.Cells["B1"]; cell.PutValue("Please enter Date in cell C3 e.g. 2018-02-18"); //Access cell B3 and add the Date Pattern cell = sheet.Cells["B3"]; cell.PutValue("Date (yyyy-mm-dd):"); // Access cell C3 and add to it custom expression validation to accept dates in yyyy-mm-dd format cell = sheet.Cells["C3"]; var validation = cell.CreateValidation(GridValidationType.CustomExpression, true); validation.RegEx = @"\d{4}-\d{2}-\d{2}"; //Set the column widths sheet.Cells.SetColumnWidth(1, 40); sheet.Cells.SetColumnWidth(2, 30); // Assigning the name of JavaScript function to OnCellErrorClientFunction property of GridWeb GridWeb1.OnCellErrorClientFunction = "ValidationErrorFunction"; }
protected void btnAddListValidation_Click(object sender, EventArgs e) { // ExStart:AddListValidation // Accessing the cells collection of the worksheet that is currently active GridWorksheet sheet = GridWeb1.WorkSheets[GridWeb1.ActiveSheetIndex]; // Access "B1" cell and add some text GridCell cell = sheet.Cells[0, 1]; cell.PutValue("Select Course:"); // Accessing "C1" cell cell = sheet.Cells[0, 2]; // Creating List validation for the "C1" cell var validation = cell.CreateValidation(GridValidationType.List, true); // Adding values to List validation var values = new System.Collections.Specialized.StringCollection(); values.Add("Fortran"); values.Add("Pascal"); values.Add("C++"); values.Add("Visual Basic"); values.Add("Java"); values.Add("C#"); validation.ValueList = values; // ExEnd:AddListValidation }
protected void btnAddDataValidation_Click(object sender, EventArgs e) { // ExStart:AddDataValidation // Access first worksheet GridWorksheet sheet = GridWeb1.WorkSheets[0]; // Access cell B3 GridCell cell = sheet.Cells["B3"]; // Add validation inside the gridcell // Any value which is not between 20 and 40 will cause error in a gridcell GridValidation val = cell.CreateValidation(GridValidationType.WholeNumber, true); val.Formula1 = "=20"; val.Formula2 = "=40"; val.Operator = GridOperatorType.Between; val.ShowError = true; val.ShowInput = true; // ExEnd:AddDataValidation Label1.Text = "Data Validation is added in cell B3. Any value which is not between 20 and 40 will cause error."; }
protected void btnAddCustomValidation_Click(object sender, EventArgs e) { // ExStart:AddCustomValidation // Accessing the cells collection of the worksheet that is currently active GridWorksheet sheet = GridWeb1.WorkSheets[GridWeb1.ActiveSheetIndex]; // Access "B1" cell and add some text GridCell cell = sheet.Cells[0, 1]; cell.PutValue("Date (yyyy-mm-dd):"); // Access "C1" cell and add to it custom expression validation to accept dates in yyyy-mm-dd format cell = sheet.Cells[0, 2]; var validation = cell.CreateValidation(GridValidationType.CustomExpression, true); validation.RegEx = @"\d{4}-\d{2}-\d{2}"; // ExEnd:AddCustomValidation sheet.Cells.SetColumnWidth(1, 30); // Assigning the name of JavaScript function to OnValidationErrorClientFunction property of GridWeb GridWeb1.OnValidationErrorClientFunction = "ValidationErrorFunction"; }
private void InitGridWeb() { // ExStart:WriteClientSideScript // Assigning the name of JavaScript function to OnSubmitClientFunction property of GridWeb GridWeb1.OnSubmitClientFunction = "ConfirmFunction"; // Assigning the name of JavaScript function to OnValidationErrorClientFunction property of GridWeb //GridWeb1.OnValidationErrorClientFunction = "ValidationErrorFunction"; // Accessing the cells collection of the worksheet that is currently active GridWorksheet sheet = GridWeb1.WorkSheets[GridWeb1.ActiveSheetIndex]; // Accessing "B1" cell and add some text GridCell cell = sheet.Cells[0, 1]; cell.PutValue("Date (yyyy-mm-dd):"); // Accessing "C1" cell and add to it custom expression validation to accept dates in yyyy-mm-dd format cell = sheet.Cells[0, 2]; var validation = cell.CreateValidation(GridValidationType.CustomExpression, true); validation.RegEx = @"\d{4}-\d{2}-\d{2}"; // ExEnd:WriteClientSideScript }