So here is what I am trying to achieve. I have multiple radgrids on a single page in a tabbed view. Some of these radgrids implement the same user control. However they pull different data. I have public properties set in the usercontrol that reference the input fields (RadTextBox, RadComboBox, Checkbox, etc.). When I implement the user control driectly on the page without binding it to a radgrid everything works properly. I can do:
where InsertItem is a method that inserts the item text into the database
However on the page with the radgrids the way the user control is bound is
with the main point being:
RadTextBox item1 = userControl1.Item1TextBox;
InsertItem(item1.Text);
However on the page with the radgrids the way the user control is bound is
protected override void OnInit(EventArgs e)
{
base.OnInit(e)
RadGrid1.Skin = Skin;
RadGrid1.Width = GridWidth;
RadGrid1.AutoGenerateColumns = false;
RadGrid1.NeedDataSource += RadGrid1_NeedDataSource;
RadGrid1.NeedDataSource += RadGrid1_InsertCommand;
RadGrid1.NeedDataSource += RadGrid1_UpdateCommand;
RadGrid1.NeedDataSource += RadGrid1_DeleteCommand;
RadGrid1.MasterTableView.Width = Unit.Percentage(100);
RadGrid1.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.Top;
RadGrid1.MasterTableView.CommandItemSettings.ShowAddNewRecordButton = true;
RadGrid1.MasterTableView.CommandItemSettings.ShowRefreshButton = false;
RadGrid1.MasterTableView.ShowHeadersWhenNoRecords = true;
RadGrid1.MasterTableView.EditFormSettings.UserControlName = "/includes/userControls/RoofForm.ascx";
RadGrid1.MasterTableView.EditFormSettings.EditFormType = GridEditFormType.WebUserControl;
RadGrid1.MasterTableView.DataKeyNames = DataKeys;
}
RadGrid1.MasterTableView.EditFormSettings.UserControlName = "/includes/userControls/RoofForm.ascx";
RadGrid1.MasterTableView.EditFormSettings.EditFormType = GridEditFormType.WebUserControl;
So my question is: Is it possible to access these public properties which return a control in the InsertCommand/UpdateCommand bindings or am I forced to use the FindControl?
For example:
protected void RadGrid1_InsertCommand(object sender, GridCommandEventArgs e)
{
UserControl userControlForm= e.Item.FindControl(GridEditFormItem.EditFormUserControlID) as UserControl;
RadComboBox item1 = userControlForm.Property1;
RadComboBox item2 = userControlForm.Property2;
RadComboBox item3 = userControlForm.Property3;
RadComboBox item4 = userControlForm.Property4;
RadComboBox item5 = userControlForm.Property5;
RadDatePicker item6 = userControlForm.Property6;
RadNumericTextBox item7 = userControlForm.Property7;
RadNumericTextBox item8 = userControlForm.Property8;
if (insert(item1.text, item2.text, item3.text, item4.text, etc..)
{
ErrorMessages.Text += "<
br
/>The item was saved but there were other errors";
}
else
{
AllSaved = false;
ErrorMessages.Text += "<
br
/>The item was not saved. Please go to the parent entry to add the item.";
}
}
If this isn't clear let me know and I will be happy to elaborate.