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

Event from controls in the Grid are not firing.

4 Answers 52 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Matthew
Top achievements
Rank 1
Matthew asked on 19 Jun 2013, 06:29 PM
Let's say I have the following Grid.

<telerik:RadGrid runat="server" ID="MyGrid">
  <MasterTableView>
    <Columns>
      <telerik:GridTemplateColumn UniqueName="DDLCol" HeaderText="PSO Standard Setting">
        <ItemTemplate>
          <asp:DropDownList runat="server" AutoPostBack="True" ID="DDL" OnSelectedIndexChanged="DDL_SelectedIndexChanged" />
        </ItemTemplate>
      </telerik:GridTemplateColumn>
    </Columns>
  </MasterTableView>
</telerik:RadGrid>

with the following Handler.

Protected Sub DDL_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
    'Do Some stuff here.
End Sub

Execution never reaches this event handler.  What am I missing, or how could I better solve this problem?

I've also tried attaching the handler in the ItemDataBound event, but this also has not worked.

Private Sub MyGrid_ItemDataBound(sender As Object, e As Telerik.Web.UI.GridItemEventArgs) Handles MyGrid.ItemDataBound
            If TypeOf (e.Item) Is GridDataItem Then
                Dim item As GridDataItem = CType(e.Item, GridDataItem)
 
                Dim DDL As DropDownList = item.FindControl("DDL")
               'databind the drop down list (this works fine of course)
 
                AddHandler DDL.SelectedIndexChanged, AddressOf DDL_SelectedIndexChanged
            End If
        End Sub

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 20 Jun 2013, 04:08 AM
Hi,

I tried to replicate the issue,but it works fine on my side.Please have a look at the below code snippet.

ASPX:
<telerik:RadGrid runat="server" ID="MyGrid">
 <MasterTableView>
    <Columns>
        <telerik:GridTemplateColumn UniqueName="DDLCol" HeaderText="PSO Standard Setting">
          <ItemTemplate>
           <asp:DropDownList runat="server" AutoPostBack="True" ID="DDL" OnSelectedIndexChanged="DDL_SelectedIndexChanged">
            <asp:ListItem Text="aa" Value="aa"></asp:ListItem>
             <asp:ListItem Text="bb" Value="bb"></asp:ListItem>
           </asp:DropDownList>
          </ItemTemplate>
        </telerik:GridTemplateColumn>
     </Columns>
 </MasterTableView>
</telerik:RadGrid>

VB:
Protected Sub DDL_SelectedIndexChanged(sender As Object, e As EventArgs)
    Response.Write("<script language='javascript'>alert('Value Changed!');</script>")
End Sub

Thanks,
Princy
0
Matthew
Top achievements
Rank 1
answered on 20 Jun 2013, 06:11 PM
Thanks for looking at this Princy

You are absolutely right, it does work as posted.  In simplifying the problem to ask my question, I missed the part giving me grief.  Adding an update panel causes the problem to present itself.

<asp:UpdatePanel>
<ContentTemplate>
<telerik:RadGrid runat="server" ID="MyGrid">
  <MasterTableView>
    <Columns>
      <telerik:GridTemplateColumn UniqueName="DDLCol" HeaderText="PSO Standard Setting">
        <ItemTemplate>
          <asp:DropDownList runat="server" AutoPostBack="True" ID="DDL" OnSelectedIndexChanged="DDL_SelectedIndexChanged" />
        </ItemTemplate>
      </telerik:GridTemplateColumn>
    </Columns>
  </MasterTableView>
</telerik:RadGrid>
</ContentTemplate>
</asp:UpdatePanel>

I can live without it suppose, but I would really like this event to trigger asynchronously.  Any suggestions?
0
Accepted
Princy
Top achievements
Rank 1
answered on 21 Jun 2013, 06:26 AM
Hi,

Please try using Ajax,Here is the code snippet.

ASPX:
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
    <ClientEvents OnRequestStart="onRequestStart"></ClientEvents>
    <AjaxSettings>
        <telerik:AjaxSetting AjaxControlID="RadGrid1">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="RadGrid1"></telerik:AjaxUpdatedControl>
            </UpdatedControls>
        </telerik:AjaxSetting>
    </AjaxSettings>
</telerik:RadAjaxManager>
<telerik:RadGrid runat="server" ID="MyGrid" DataSourceID="SqlDataSource2" AutoGenerateColumns="false">
    <MasterTableView>
        <Columns>
            <telerik:GridTemplateColumn UniqueName="DDLCol" HeaderText="PSO Standard Setting">
                <ItemTemplate>
                    <asp:DropDownList runat="server" AutoPostBack="true" EnableViewState="true" ID="DDL"
                        OnSelectedIndexChanged="DDL_SelectedIndexChanged">
                        <asp:ListItem Text="aa" Value="aa"></asp:ListItem>
                        <asp:ListItem Text="bb" Value="bb"></asp:ListItem>
                    </asp:DropDownList>
                </ItemTemplate>
            </telerik:GridTemplateColumn>
        </Columns>
    </MasterTableView>
</telerik:RadGrid>

Thanks,
Princy
0
Matthew
Top achievements
Rank 1
answered on 21 Jun 2013, 05:42 PM
That worked perfectly Princy, thanks again for your time. 
Tags
Grid
Asked by
Matthew
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Matthew
Top achievements
Rank 1
Share this question
or