I am trying to add a new row on the client side using through a function when a user clicks a button. I keep getting and error "Async request failed [InvalidCastException]: Specified cast is not valid. Why am I getting this error? I have tried inserting using an integer and a string and still no luck. Also, I have tried to insert a new row without setting the first element of the array and I receive an error that the datakeyfield is null. The first element of my array is the DataKeyField and that Bound column is using a dropdownprovider.
function add() {
var grid = $find('<%= _ultraGridEmployees.ClientID %>')
var DropdownList = document.getElementById('<%=ddlPayType.ClientID %>');
var SelectedIndex = DropdownList.selectedIndex;
var SelectedValue = DropdownList.options[DropdownList.selectedIndex].value;
var SelectedText = DropdownList.options[DropdownList.selectedIndex].text;
var rows = grid.get_rows();
var newRow = new Array(grid.get_columns().get_length()); // create a new empty row
newRow[0] = SelectedValue;
rows.add(newRow);
}
Please advise.
Thanks!
Thanks for your help!!!
Hello,If you have any other questions do not hesitate to ask us.
Hello Brad,I would like to advise you to take a look at the following blog post http://blogs.infragistics.com/aspnet/articles/webdatagrid-client-side-crud.aspx and the following forum thread - http://blogs.infragistics.com/forums/p/30661/169251.aspx where a discussion about client side row adding are made. From the code snipped you have pasted I could not determine where the issue comes from. My suggestion is to debug and check if you are inserting the same number of fields, or if there are some fields which could not be null or if the set value from the DropDownList is of the same type as the value of the first column of the grid. If it is possible attach a small sample which reproduces the error.