get itemdata on dropdownlist event of gridtemplatecolumn

3 posts, 0 answers
  1. Jota
    Jota avatar
    7 posts
    Member since:
    Dec 2014

    Posted 30 Jul 2015 Link to this post

    Hello! I'm working with a RadGrid with HierarchyLoadMode="Client", in the second level of detailTables  I have a GridTemplateColumn with a dropdownlist like this:

    <telerik:GridTemplateColumn HeaderText="Alta Petició" HeaderStyle-HorizontalAlign="Center" UniqueName="UNDDLAltaTop" ItemStyle-HorizontalAlign="left">
    <ItemTemplate>
              <asp:DropDownList ID="DDLTP" runat="server" OnSelectedIndexChanged="DDLTP_SelectedIndexChanged" />
    </ItemTemplate>
    </telerik:GridTemplateColumn>

     I'm set datasource of DDLTP in itemDataBound event:

     

    if (e.Item.OwnerTableView.Name == "Son")
    {
        if (e.Item is GridDataItem)
        {
            GridDataItem item = (GridDataItem)e.Item;
            DropDownList ddl = (DropDownList)item["UNDDLAltaTop"].FindControl("DDLTP");
            setDatasource(ref ddl, "ID_TP"); 
        
    }

    This works perfect!

     

    Now I need to access to itemdata like (ItemCommand Event) to get the value of another column of the row

    protected void DDLTP_SelectedIndexChanged(object sender, EventArgs e)
    {
     
    }

     

    If I use an imagebutton to make the postback i can access itemData with ItemCommand Event but I don't like this solution:

    <telerik:GridTemplateColumn HeaderText="Alta Petició" HeaderStyle-HorizontalAlign="Center" UniqueName="UNDDLAltaTop" ItemStyle-HorizontalAlign="left">
    <ItemTemplate>
              <asp:DropDownList ID="DDLTP" runat="server"/>
              <asp:ImageButton  ID="BAltaPeticio" runat="server" CommandName="Altapeticio"           ImageUrl="../../Imatges/b_Add.gif" ToolTip="Alta Petició" />
    </ItemTemplate>
    </telerik:GridTemplateColumn>

    Can you help me??

     

    thanks

     

     

     

     

     

  2. Jota
    Jota avatar
    7 posts
    Member since:
    Dec 2014

    Posted 03 Aug 2015 Link to this post

    I'm try in itemdataboun event this:

     but not works... another idea? please

    if (e.Item.OwnerTableView.Name == "son")
    {
        if (e.Item is GridDataItem)
        {
            GridDataItem item = (GridDataItem)e.Item;
            DropDownList ddl =DropDownList)item["UNDDLAltaTop"].FindControl("DDLTP");
            setDataSource(ref ddl, "ID_TP);
            ddl.Attributes.Add("CommandName", "ddlEvent"); 
        
    }

  3. Eyup
    Admin
    Eyup avatar
    3699 posts

    Posted 04 Aug 2015 Link to this post

    Hello Jota,

    You can access the container grid item using the following approach:
    protected void DDLTP_SelectedIndexChanged(object sender, EventArgs e)
    {
        DropDownList list = (DropDownList)sender;
        GridDataItem item = (GridDataItem)list.NamingContainer;
    }

    Once you have a reference to the item, you can extract the desired values:
    http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/rows/accessing-cells-and-rows#accessing-raw-field-data-and-key-values

    Hope this helps.

    Regards,
    Eyup
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top