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

Attach an event to a DropDownList in form Template

2 Answers 104 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Lakshman Venkat
Top achievements
Rank 1
Lakshman Venkat asked on 17 Jun 2008, 06:25 PM

I am trying to attach an event to a DropdownList which is part of my Edit Form. But the SlectedIndex_changed event doesn't fire even though when I select it does a postback. Appreciate any help

                    <telerik:RadGrid    ID="rgContactNumber"
                                        OnItemCommand="rgContactNumber_ItemCommand"
                                        OnItemDataBound="rgContactNumber_ItemDataBound"
                                        OnNeedDataSource="rgContactNumber_NeedDataSource"
                                        OnUpdateCommand="rgContactNumber_UpdateCommand"
                                        AllowAutomaticDeletes="True" AllowAutomaticUpdates="True"
                                        AllowAutomaticInserts="true" AllowPaging="True"
                                        AllowSorting="True" AutoGenerateColumns="False" 
                                        EnableAJAX="True"
                                        GridLines="Horizontal" runat="server" Width="98%"
                                        EnableAJAXLoadingTemplate="False"
                                        LoadingTemplateTransparency="0"
                                        PageSize="5">
                        <ClientSettings>
                            <Scrolling AllowScroll="True" UseStaticHeaders="False" />
                            <Selecting AllowRowSelect="True" />
                        </ClientSettings>                         
                        <MasterTableView Width="100%" GridLines="Horizontal" DataKeyNames="ContactID" PageSize="5"
                                             AutoGenerateColumns="False"  CommandItemDisplay="TopAndBottom">
                            <CommandItemTemplate>
                                <table>
                                    <tr>
                                        <td width="30%">
                                            <asp:LinkButton ID="btnAdd" Text="Add Contact Number" CommandName="InitInsert" runat="server"/>
                                        </td>
                                    </tr>
                                </table>
                            </CommandItemTemplate>
                            <Columns>
                                <telerik:GridEditCommandColumn  ButtonType="ImageButton"
                                                                UpdateImageUrl="../App_Themes/Default/DataEditingImages/Edit.gif"
                                                                CancelImageUrl="../App_Themes/Default/DataEditingImages/Cancel.gif">
                                </telerik:GridEditCommandColumn>
                                <telerik:GridBoundColumn    DataField="ContactId" Groupable="False" HeaderText="Contact Id"
                                                            UniqueName="ContactIdColumn" ReadOnly="True" Visible="false">
                                </telerik:GridBoundColumn>                     
                                <telerik:GridBoundColumn    DataField="ContactValue" HeaderText="Phone Number"
                                                            SortExpression="ContactValue" UniqueName="ContactValue">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn    DataField="ContactSubType.Description" HeaderText="Contact Type"
                                                            SortExpression="ContactSubType.Description"
                                                            UniqueName="PhoneType" ReadOnly="true" Visible="true">
                                </telerik:GridBoundColumn>  
                                <telerik:GridBoundColumn    DataField="ContactDescription" HeaderText="Describe Other"
                                                            SortExpression="ContactDescription" UniqueName="ContactDescription"
                                                            Visible="false">
                                </telerik:GridBoundColumn>
                                <telerik:GridCheckBoxColumn DataField="IsPrimary" HeaderText="Primary"
                                                UniqueName="Primary" Visible="true"> 
                                </telerik:GridCheckBoxColumn> 
                                <telerik:GridDropDownColumn HeaderText="Phone Type" UniqueName="ddlPhoneType" Visible="false"
                                                            ListValueField="ContactSubTypeID"
                                                            ListTextField="Description"
                                                            DropDownControlType="DropDownList">
                                </telerik:GridDropDownColumn>                                                           
                                <telerik:GridButtonColumn   ConfirmText="Are you sure you want to Delete this Contact?"
                                                            ButtonType="ImageButton"
                                                            ImageUrl="../App_Themes/Default/DataEditingImages/Delete.gif"
                                                            CommandName="Delete"
                                                            Text="Delete"
                                                            UniqueName="DeleteColumn">
                                <HeaderStyle Width="20px"/>
                                </telerik:GridButtonColumn>                
                            </Columns>
                            <EditFormSettings EditFormType="Template">
                                <FormTemplate>
                                    <table id="Table2" cellspacing="2" cellpadding="1" width="100%" border="0" rules="none" style="border-collapse: collapse;background:white;">
                                        <tr>
                                            <td colspan="2" style="font-size: small"><b>Contact Details</b></td>
                                    </tr>
                                    <tr>
                                        <td>
                                            <table id="Table3" cellspacing="1" cellpadding="1" width="250" border="0">
                                                <tr>
                                                    <td>
                                                    </td>
                                                    <td>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>Phone Number</td>
                                                    <td><asp:TextBox ID="txtContactValue" runat="server" Text='<%# Bind( "ContactValue" ) %>'/></td>
                                                </tr>
                                                <tr>
                                                    <td>Phone Type</td>
                                                    <td>
                                                        <asp:DropDownList   ID="ddlPhoneType"
                                                                            DataSourceID="odsContactSubTypes"
                                                                            DataTextField="Description"
                                                                            DataValueField="ContactSubtypeID"
                                                                            runat="server"
                                                                            AutoPostBack="true"
                                                                            ShowToggleImage="True"
                                                                            Width="150px">
                                                        </asp:DropDownList>                                                                    
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>Is Primary</td>
                                                    <td><asp:CheckBox ID="chkIsPrimary" runat="server"/></td>
                                                </tr>
                                                <tr>
                                                    <td>Describe Other</td>
                                                    <td><asp:TextBox ID="txtContactDescription" runat="server" Visible="false"/></td>
                                                </tr>                                       
                                                <tr>
                                                    <td align="right" colspan="2">
                                                        <asp:Button ID="btnUpdate"
                                                                    Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>'
                                                                    runat="server"
                                                                    CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'>
                                                        </asp:Button>&nbsp;
                                                        <asp:Button ID="btnCancel"
                                                                    Text="Cancel"
                                                                    runat="server"
                                                                    CausesValidation="False"
                                                                    CommandName="Cancel">
                                                        </asp:Button>
                                                    </td>
                                                </tr>
                                            </table>
                                    </FormTemplate>
                            </EditFormSettings>               
                        </MasterTableView>
                    </telerik:RadGrid>

Here is the Code Behind

    protected void rgContactNumber_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridEditFormItem && e.Item.IsInEditMode)
        {
            GridEditFormItem item = e.Item as GridEditFormItem;
            DropDownList ddl = (DropDownList)item.FindControl("ddlPhoneType");
            ddl.AutoPostBack = true;
            ddl.SelectedIndexChanged += new EventHandler(ddl_SelectedIndexChanged);
            ddl.DataSource = CollateralPartyBLO.GetContactSubTypes();
            ddl.DataBind();
        }
    }

    protected void ddl_SelectedIndexChanged(object sender, EventArgs e)
    {
        int id = ddl.SelectedIndex;
    }

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 18 Jun 2008, 04:23 AM
Hi Lakshman,

Can you try setting the SelectedIndexChanged event handler in the aspx and see whether it is firing?

ASPX:
 <asp:DropDownList ID="DropDownList1" runat="server" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"
        </asp:DropDownList> 


Shinu.
0
Stephen
Top achievements
Rank 1
answered on 06 Nov 2008, 04:54 PM

Hi.  I'm using a radCombobox and I had to do the following: 

 

 

ddl.SelectedIndexChanged +=

new RadComboBoxSelectedIndexChangedEventHandler(ddl_SelectedIndexChanged);

 

 

Hope this helps. 

 

Tags
Grid
Asked by
Lakshman Venkat
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Stephen
Top achievements
Rank 1
Share this question
or