I have the following requirement in my project
Requirement 1:
On external button click we are adding a new row in webdatagrid and we are able to add the row successfully using JavaScript.
But our requirement is to make added row editable not the entire webdatagrid by using javascript.
Requirement 2:
2) On clicking of external button click we are making the webdatagrid editable but some columns are read only. We want to make editable columns as textbox
Requirement 3:
3) We are unable to validate required field validation in webdatagrid for Datetimepicker and numeric columns
this is urgent please help.
Hello,
Your first requirement can be achieved by enabling the Editing behavior in your grid and cancelling entering edit mode on all cases except for the recently added row.
Please provide more details on the last 2 requirements. For requirement 2, please elaborate on making editable columns as text box and how it differs from the default behavior when the editting behavior is active. For requirement 3, please provide more details on how you are handling validation of the DateTimePicker.
Thank you for your reply.
Could you please provide some sample code for requirement one.
Regarding second requirement we have an external edit button on clicking of the edit button we have to make some columns in the webdatagrid as editable.
those editable columns need to be highlighted as textboxes so that user will be knowing what columns are editable.
Regarding 3 requirement
<asp:RequiredFieldValidator ID="RequiredFieldValidatorForTest" ControlToValidate="WebDataGridTest"
CssClass="error" Enabled="false" runat="server" ErrorMessage="Description is required!">asp:RequiredFieldValidator>
Incode behind
TextEditorProvider textBox = new TextEditorProvider();
RequiredFieldValidatorForDesc.Enabled = true;
textBox.ID = "TextEditorProvider1";
textBox.EditorControl.MaxLength = 255;
EditingColumnSetting columnSettingDesc = new EditingColumnSetting();
columnSettingDesc.ColumnKey = "Description";
columnSettingDesc.EditorID = textBox.ID;
columnSettingDesc.ValidatorID = "RequiredFieldValidatorForDesc"; I am able to do for textbox .
But I am not able to do for
DatePickerProvider datePickerProvider = new DatePickerProvider();
datePickerProvider.ID = "DatePickerProvider1";
datePickerProvider.EditorControl.MinValue = DateTime.Now;
// Add to collection
Hello DeviKiran,
I am attaching a sample that demonstrates the first two requirements.
For your first requirement, we can add a row from the client side by following the documentation found here: http://help.infragistics.com/doc/ASPNET/2015.2/CLR4.0/?page=WebDataGrid_Row_Adding.html. Now, the missing part is only allowing edit mode to enter when the row is recently added. Given that the editting behavior is enabled, it can be assumed that a DataKeyFields property is set which is a unique identifier for every row. Therefore, the value of the DataKeyField can be pushed into an array when adding a new row programmatically and when entering edit mode, the value can be checked if it is available in the array and, if the value is not in the array, the entering edit mode event can be cancelled:
function checkRecentlyAdded(sender, e) { if (addedRows.indexOf(e.getCell().get_row().get_dataKey()[0]) == -1) e.set_cancel(true);}
The second requirement can be achieved by toggling the readOnly property during a button's OnClick event from the server:
protected void button1_Click(object sender, EventArgs e){ WDG1.Behaviors.EditingCore.Behaviors.CellEditing.ColumnSettings["UnitsInStock"].ReadOnly = !WDG1.Behaviors.EditingCore.Behaviors.CellEditing.ColumnSettings["UnitsInStock"].ReadOnly;}
For your third requirement, here is a video detailing how to add validation to the WebDataGrid:
https://www.youtube.com/watch?v=bkmGNG9ViDQ