Hi.
I have a grid with a comboBox that use the event SelectedIndexChanged. AutoPostBack is set to true. The problem is that the event handler does not fired every time the comboBox index changed (in insert-mode), nearly never. When the index changed and it has not fired and i fill in values in some RadTextBox, then it fired when i save the new record. (I have also tried to use the OnTextChanged event and same happens here.) The comboBox contain a list of companies and i use LinqDataSoure to get the companies.
Here is the code i am using and the comboBox that not work correctly is with the id= Company :
I have a grid with a comboBox that use the event SelectedIndexChanged. AutoPostBack is set to true. The problem is that the event handler does not fired every time the comboBox index changed (in insert-mode), nearly never. When the index changed and it has not fired and i fill in values in some RadTextBox, then it fired when i save the new record. (I have also tried to use the OnTextChanged event and same happens here.) The comboBox contain a list of companies and i use LinqDataSoure to get the companies.
Here is the code i am using and the comboBox that not work correctly is with the id= Company :
protected
void
CompanyComboBox_SelectedIndexChanged(
object
sender, RadComboBoxSelectedIndexChangedEventArgs e)
{
var combo = (RadComboBox) sender;
if
(combo ==
null
)
return
;
var item = combo.NamingContainer
is
GridEditFormInsertItem ? (GridEditFormInsertItem)combo.NamingContainer : (GridEditFormItem)combo.NamingContainer;
var userNumberBox = (RadNumericTextBox)item.FindControl(
"UserNumber"
);
string
userNumber = userNumberBox.Text;
string
companyId = combo.SelectedValue;
if
(
string
.IsNullOrEmpty(userNumber) ||
string
.IsNullOrEmpty(companyId))
return
;
var firstNameBox = (RadTextBox)item.FindControl(
"FirstName"
);
var lastNameBox = (RadTextBox)item.FindControl(
"lastName"
);
User user = GetUser(userNumber, companyId);
if
(user !=
null
)
{
firstNameBox.Text = user.FirstName;
lastNameBox.Text = user.LastName;
}
else
{
firstNameBox.Text =
string
.Empty;
lastNameBox.Text =
string
.Empty;
}
}
<
EditFormSettings
EditFormType
=
"Template"
>
<
EditColumn
UniqueName
=
"EditCommandColumn1"
></
EditColumn
>
<
FormTemplate
>
<
div
id
=
"column1"
style
=
"float:left;padding:10px;"
>
<
div
style
=
"padding-bottom:7px;"
>
<
table
>
<
tr
><
td
><
asp:Label
ID
=
"NumberLabel"
runat
=
"server"
Text
=
"Brukernr.:"
></
asp:Label
></
td
><
td
><
telerik:RadNumericTextBox
runat
=
"server"
OnTextChanged
=
"UserNumberTextBox_TextChanged"
AutoPostBack
=
"true"
ID
=
"UserNumber"
Width
=
"107"
DataType
=
"System.Int32"
><
NumberFormat
DecimalDigits
=
"0"
GroupSeparator
=
""
/></
telerik:RadNumericTextBox
><
asp:RequiredFieldValidator
ID
=
"RequiredFieldValidator1"
Text
=
"*"
ForeColor
=
"Red"
ControlToValidate
=
"UserNumber"
runat
=
"server"
/>
<
asp:Label
ID
=
"Label21"
runat
=
"server"
Text
=
"Aktiv"
></
asp:Label
>
<
telerik:RadComboBox
runat
=
"server"
ID
=
"RadComboBoxActive"
Width
=
"45px"
DataValueField
=
"IsActive"
AutoPostBack
=
"true"
>
<
Items
>
<
telerik:RadComboBoxItem
Value
=
"1"
Text
=
"Ja"
/>
<
telerik:RadComboBoxItem
Value
=
"0"
Text
=
"Nei"
/>
</
Items
>
</
telerik:RadComboBox
></
td
></
tr
>
<
tr
><
td
><
asp:Label
ID
=
"CompanyLabel"
runat
=
"server"
Text
=
"Selskap/Avd.:"
></
asp:Label
></
td
>
<
td
colspan
=
"2"
><
telerik:RadComboBox
ID="Company" runat
=
"server"
OnSelectedIndexChanged
=
"CompanyComboBox_SelectedIndexChanged"
CausesValidation
=
"true"
AutoPostBack
=
"true"
DataSourceID
=
"CompanyDataSource"
DataTextField
=
"Name"
DataValueField
=
"CompanyId"
EmptyMessage
=
"Velg et element"
AllowCustomText
=
"true"
></
telerik:RadComboBox
>
<
asp:RequiredFieldValidator
ID
=
"RequiredFieldValidator3"
Text
=
"*"
ForeColor
=
"Red"
ControlToValidate
=
"Company"
runat
=
"server"
/></
td
></
tr
>
</
table
>
</
div
>
</
div
>
<
div
id
=
"column1b"
style
=
"float:left;padding:10px;"
>
<
div
style
=
"padding-bottom:7px;"
>
<
table
>
<
tr
><
td
><
asp:Label
ID
=
"FirstNameLabel"
runat
=
"server"
Text
=
"Fornavn:"
></
asp:Label
></
td
><
td
><
telerik:RadTextBox
ID
=
"FirstName"
runat
=
"server"
Width
=
"150"
MaxLength
=
"20"
></
telerik:RadTextBox
><
asp:RequiredFieldValidator
ID
=
"RequiredFieldValidator2"
Text
=
"*"
ForeColor
=
"Red"
ControlToValidate
=
"FirstName"
runat
=
"server"
/></
td
></
tr
>
<
tr
><
td
><
asp:Label
ID
=
"LastNameLabel"
runat
=
"server"
Text
=
"Etternavn:"
></
asp:Label
></
td
><
td
><
telerik:RadTextBox
ID
=
"LastName"
runat
=
"server"
Width
=
"150"
MaxLength
=
"20"
></
telerik:RadTextBox
><
asp:RequiredFieldValidator
ID
=
"RequiredFieldValidator8"
Text
=
"*"
ForeColor
=
"Red"
ControlToValidate
=
"LastName"
runat
=
"server"
/></
td
></
tr
>
</
table
>
</
div
>
</
div
>