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

get itemdata on dropdownlist event of gridtemplatecolumn

2 Answers 26 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jota
Top achievements
Rank 1
Jota asked on 30 Jul 2015, 06:47 AM

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 Answers, 1 is accepted

Sort by
0
Jota
Top achievements
Rank 1
answered on 03 Aug 2015, 08:31 AM

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"); 
    
}

0
Eyup
Telerik team
answered on 04 Aug 2015, 06:34 AM
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
Tags
Grid
Asked by
Jota
Top achievements
Rank 1
Answers by
Jota
Top achievements
Rank 1
Eyup
Telerik team
Share this question
or