Hi
I have a grid control which uses a template for the editing/inserting. In my template, I have my own user control which has a property which is usually databound.
When inserting by pressing the insert command in the grid command item template, I look out for the InitInsertCommandName, and create some default values for the insert template, like so:
protected void radApprovers_ItemCommand(object source, GridCommandEventArgs e)
{
if (e.CommandName == RadGrid.InitInsertCommandName)
{
// Cancel the default operation
e.Canceled = true;
//Prepare an IDictionary with the predefined values
System.Collections.Specialized.ListDictionary newValues = new System.Collections.Specialized.ListDictionary();
newValues["company_id"] = cmbCompaniesFilter.SelectedCompanyId;
//Insert the item and rebind
e.Item.OwnerTableView.InsertItem(newValues);
}
}
As you can see, I'm setting the default values for the column company_id. Here's the problem:
I want to put the grid into insert mode dynamically (which I'm doing through a page url request variable). I'm using the following code to do so:
System.Collections.Specialized.ListDictionary newValues = new System.Collections.Specialized.ListDictionary();
newValues["account_id"] = SessionManager.GetAccountId(this);
newValues["company_id"] = cmbCompaniesFilter.SelectedCompanyId;
gridApprovers.MasterTableView.IsItemInserted = true;
gridApprovers.MasterTableView.InsertItem(newValues);
The problem is that when I call InsertItem(newValues) I get the following error:
"Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.". I have to set a value here, otherwise it tries to bind a DBNull to an integer property, which will raise a "Specified cast is not valid" error when it binds.
Can you please tell me how I can go about dynamically creating databinding values when dynamically setting the grid into Insert mode?
Thanks
I have a grid control which uses a template for the editing/inserting. In my template, I have my own user control which has a property which is usually databound.
When inserting by pressing the insert command in the grid command item template, I look out for the InitInsertCommandName, and create some default values for the insert template, like so:
protected void radApprovers_ItemCommand(object source, GridCommandEventArgs e)
{
if (e.CommandName == RadGrid.InitInsertCommandName)
{
// Cancel the default operation
e.Canceled = true;
//Prepare an IDictionary with the predefined values
System.Collections.Specialized.ListDictionary newValues = new System.Collections.Specialized.ListDictionary();
newValues["company_id"] = cmbCompaniesFilter.SelectedCompanyId;
//Insert the item and rebind
e.Item.OwnerTableView.InsertItem(newValues);
}
}
As you can see, I'm setting the default values for the column company_id. Here's the problem:
I want to put the grid into insert mode dynamically (which I'm doing through a page url request variable). I'm using the following code to do so:
System.Collections.Specialized.ListDictionary newValues = new System.Collections.Specialized.ListDictionary();
newValues["account_id"] = SessionManager.GetAccountId(this);
newValues["company_id"] = cmbCompaniesFilter.SelectedCompanyId;
gridApprovers.MasterTableView.IsItemInserted = true;
gridApprovers.MasterTableView.InsertItem(newValues);
The problem is that when I call InsertItem(newValues) I get the following error:
"Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.". I have to set a value here, otherwise it tries to bind a DBNull to an integer property, which will raise a "Specified cast is not valid" error when it binds.
Can you please tell me how I can go about dynamically creating databinding values when dynamically setting the grid into Insert mode?
Thanks