This is a migrated thread and some comments may be shown as answers.

GridDropDownColumn selectedIndexChanged event stop firing after applying RequiredFieldValidator

7 Answers 317 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ozgur
Top achievements
Rank 1
Ozgur asked on 25 Nov 2011, 10:00 AM
Hi, I hope I can explain my problem clearly.

I have RadGrid with two GridDropDownColumns and some other RadNumericTextBox columns.

One of the GridDropDownColumn is filtered based on the selected value from the other GridDropDownColumn.

I was able to fire SelectedIndexChange event at this point. The event stop firing after I applies RequiredFieldValidator on one of my RadNumericTextBox. 

When the grid is in edit mode, everything is fine if I just select the combobox to filter the other one, However, once I try to update and it failed because of RequiredFiedValidator. The combobox' selectIndexChange event can not be fired anymore.

My code are following
ASCX
<Columns>
    <telerik:GridDropDownColumn UniqueName="Combo1" DropDownControlType="RadComboBox" DataField="Combo1data" DataSourceID="odcCombo1" ListValueField="Description1" ListTextField="Description1" ColumnEditorID="edtCombo1"  HeaderText="Main" HeaderStyle-Width="120px" ItemStyle-Width="120px"></telerik:GridDropDownColumn>
    <telerik:GridDropDownColumn UniqueName="Combo2" DropDownControlType="RadComboBox" DataField="Combo2data" DataSourceID="odcCombo2" ListValueField="Description2" ListTextField="Description2" ColumnEditorID="edtCombo2" HeaderText="Depend" HeaderStyle-Width="100px" ItemStyle-Width="100px"></telerik:GridDropDownColumn>
    <telerik:GridTemplateColumn UniqueName="NumData1" DataField="Data1" ItemStyle-ForeColor="Black" HeaderText="NumData" ItemStyle-Width="55px" HeaderStyle-Width="55px" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center" >
    <ItemTemplate>
        <asp:Label runat="server" ID="lblData1" Text='<%# Eval("Data1", "{0:C}") %>'></asp:Label>
    </ItemTemplate>
    <EditItemTemplate>
    <span><telerik:RadNumericTextBox runat="server" ID="tbData1" Width="55px" DbValue='<%# Bind("Data1") %>' MinValue="10000000" MaxValue="99999999" MaxLength="8"><NumberFormat DecimalDigits="0" GroupSeparator="" />
        </telerik:RadNumericTextBox><span style="color: Red"><asp:RequiredFieldValidator ID="RequiredFieldValidator1" ControlToValidate="tbData1" ErrorMessage="*" runat="server"></asp:RequiredFieldValidator>
    </span>
    </EditItemTemplate>
ASCX.CS
        protected void grdTimeCard_ItemCreated(object sender, GridItemEventArgs e)
        {
            //create fire event when it's in edit mode
            if (e.Item is GridEditableItem && e.Item.IsInEditMode)
            {
                GridEditableItem editItem = (GridEditableItem)e.Item;
                GridDropDownListColumnEditor editor = (GridDropDownListColumnEditor)editItem.EditManager.GetColumnEditor("Entry");
                editor.ComboBoxControl.AutoPostBack = true;
                editor.ComboBoxControl.SelectedIndexChanged += new RadComboBoxSelectedIndexChangedEventHandler(list_SelectedIndexChanged);
            }
        }
  
        private void list_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
{
}

protected void grdTimeCard_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridEditableItem && e.Item.IsInEditMode)
    {
        string defaultCombo1 = "";
        GridDataItem dataItem = e.Item as GridDataItem;
        GridEditableItem editItem = (GridEditableItem)e.Item;
        //do nothing if it's insert itme
        if (e.Item is GridDataInsertItem)
        {
        }
        else
        {
            // if it's edit mode
            defaultCombo1 = ((DataRowView)e.Item.DataItem)["Combo1"].ToString();
            try
            {
                RequiredFieldValidator validator1 = (RequiredFieldValidator)editItem.FindControl("RequiredFieldValidator1");
                if (defaultCombo1 == "Regular" )
                    validator1.Enabled = true;
                else
                    validator1.Enabled = false;


Any suggestions?

7 Answers, 1 is accepted

Sort by
0
Tsvetina
Telerik team
answered on 25 Nov 2011, 04:19 PM
Hello Ozgur,

Have you tried using different validation groups inside the edit form? Currently the required field validator prevents all postbacks when the textbox is not filled but if you give a ValidationGroup name to it, the textbox and the Insert/Update button, the autopostback functionality of the combos should not be affected.

Regards,
Tsvetina
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Ozgur
Top achievements
Rank 1
answered on 25 Nov 2011, 05:36 PM
Hi Tsvetina,

Thank you for the quick reply. I was trying to add the ValidationGroup into my button, but there is no such attribute in both GridButtonColumn and GridEditCommandColumn.

Do I have to convert them to ASP button? Please advise.
 
    <telerik:GridButtonColumn CommandName="Delete" Text="Delete" UniqueName="DeleteColumn" ButtonType="ImageButton" ItemStyle-Width="16px" HeaderStyle-Width="16px" ItemStyle-HorizontalAlign="Center"></telerik:GridButtonColumn>
    <telerik:GridEditCommandColumn ButtonType="ImageButton" ItemStyle-Width="42px" ItemStyle-HorizontalAlign="Right" HeaderText="Edit      " HeaderStyle-Wrap="false"  HeaderStyle-Width="42px"></telerik:GridEditCommandColumn>
</Columns>
0
Jayesh Goyani
Top achievements
Rank 2
answered on 25 Nov 2011, 05:57 PM
Hello,

set below property.

<telerik:RadComboBox CausesValidation="false"


Thanks,
Jayesh Goyani
0
Ozgur
Top achievements
Rank 1
answered on 25 Nov 2011, 06:10 PM
Hi Jayesh,

Thank you for your reply. I am using <telerik:GridDropDownColumn for the downdownlist. There is no CausesValidation attribute. Is there something else I can set?
0
Jayesh Goyani
Top achievements
Rank 2
answered on 25 Nov 2011, 06:18 PM
Hello,

protected void RadGrid1_ItemDataBound(object sender, Telerik.WebControls.GridItemEventArgs e) {
if (e.Item is GridEditableItem && e.Item.IsInEditMode)
{
 GridEditableItem editedItem = e.Item as GridDataItem;
 GridEditManager editMan = editedItem.EditManager;
 
 GridDropDownListColumnEditor editor = (GridDropDownListColumnEditor)(editMan.GetColumnEditor( "DropDownColumn"));
 DropDownList ddList = editor.DropDownListControl;
ddlList.CauseValidation = false;
}
}

Note :
GridDropDownColumnEditor editor =
      editMan.GetColumnEditor(
"DropDownColumnUniqueName" ) as GridDropDownColumnEditor;
Thanks,
Jayesh Goyani
0
Supriya
Top achievements
Rank 1
answered on 27 Sep 2012, 02:46 PM
Hello,

I am working on the selected index change event of the dropdownlist column in insert,delete and update radgridview.. And I get a strange error. I have pasted the code and error below

Protected Sub gvInsert_ItemCreated(ByVal sender As Object, ByVal e As GridItemEventArgs)
 
        If TypeOf e.Item Is GridEditFormItem AndAlso e.Item.IsInEditMode Then
            Dim item As GridEditFormItem = DirectCast(e.Item, GridEditFormItem)
            Dim editor As GridDropDownListColumnEditor = DirectCast(item.EditManager.GetColumnEditor("UniqueID"), GridDropDownListColumnEditor)

            'handle selected change on server
            editor.ComboBoxControl.AutoPostBack = True
            editor.ComboBoxControl.SelectedIndexChanged += New RadComboBoxSelectedIndexChangedEventHandler(AddressOf list_SelectedIndexChanged)
        End If
    End Sub

    
    Private Sub list_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)

        Dim editedItem As GridEditableItem = TryCast(TryCast(sender, DropDownList).NamingContainer, GridEditableItem)

    End Sub



Error:Public Event SelectedIndexChanged(sender As Object, e As Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs)' is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event.


Can someone please help get thru this error, I have been trying to solve this for the past 2 weeks..
Any help will be appreciated

Thanks,
0
Tsvetina
Telerik team
answered on 28 Sep 2012, 08:05 AM
Hello Supriya,

Attaching events dynamically in VB is done differently, try with:
AddHandler editor.ComboBoxControl.SelectedIndexChanged, AddressOf  list_SelectedIndexChanged


Kind regards,
Tsvetina
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Ozgur
Top achievements
Rank 1
Answers by
Tsvetina
Telerik team
Ozgur
Top achievements
Rank 1
Jayesh Goyani
Top achievements
Rank 2
Supriya
Top achievements
Rank 1
Share this question
or