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

[Solved] Selecting RadComboBox value in GridTemplateColumn

3 Answers 227 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ahrensberg
Top achievements
Rank 1
Ahrensberg asked on 18 Feb 2010, 04:44 PM
Hi all,

I'm sure you understand my code beneath, but how could this be done better? Not really like this "selection-hack"...

GridTemplateColumn:
<telerik:GridTemplateColumn HeaderText="<%$ Resources:LanguageWeb, OrderLine_Paragraph %>" 
    UniqueName="ParagraphId" HeaderStyle-Width="200px">
    <ItemTemplate>  
        <telerik:RadComboBox runat="server" ID="CbParagraph" OnInit="CbParagraph_Init" ToolTip='<%# Bind("Paragraph.id") %>' /> 
    </ItemTemplate>  
</telerik:GridTemplateColumn> 

The combobox items is loaded in the OnInit event, and selection done in the ItemDataBound on the RadGrid like this:
protected void RadGrid_ItemDataBound(object sender, GridItemEventArgs e) 
    if (!(e.Item is GridDataItem)) return; 
    var gridItem = (GridDataItem)e.Item; 
 
    var cbParagraphControl = gridItem.FindControl("CbParagraph"); 
    if (cbParagraphControl is RadComboBox) 
    { 
        var cbParagraph = (RadComboBox) cbParagraphControl; 
        cbParagraphcbParagraph.SelectedValue = cbParagraph.ToolTip; 
        cbParagraph.ToolTip = ""
    } 

Any ideas?

Cheers, Ahrensberg

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 19 Feb 2010, 06:25 AM
Hello,

I use the following code in order to access the RadComboBox which is placed in ItemTemplate of GridTemplateColumn.

C#:
 
    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
        if (e.Item is GridDataItem) 
        { 
            GridDataItem item = (GridDataItem)e.Item; 
            RadComboBox combo = (RadComboBox)item.FindControl("CbParagraph"); 
            // Now set the combo SelectedValue 
        } 
    } 

-Shinu.
0
Ahrensberg
Top achievements
Rank 1
answered on 19 Feb 2010, 07:20 AM
Hi Shinu,

Isn't it the just the same as I do? :o)

Best regards,
Ahrensberg
0
Iana Tsolova
Telerik team
answered on 23 Feb 2010, 03:16 PM
Hi Ahrensberg,

Try modifying the code as below and se if it makes any difference:

protected void RadGrid_ItemDataBound(object sender, GridItemEventArgs e)  
{  
    if (!(e.Item is GridDataItem)) return;  
    var gridItem = (GridDataItem)e.Item;  
    
    var cbParagraphControl = gridItem["ParagraphId"].FindControl("CbParagraph");  
    if (cbParagraphControl is RadComboBox)  
    {  
        var cbParagraph = (RadComboBox) cbParagraphControl;  
        cbParagraphcbParagraph.SelectedValue = cbParagraph.ToolTip;  
        cbParagraph.ToolTip = "";  
    }  
}


For more information on accessing grid cells and rows, please refer to the below help topic:
http://www.telerik.com/help/aspnet-ajax/grdaccessingcellsandrows.html


Best wishes,
Iana
the Telerik team

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 Public Issue Tracking system and vote to affect the priority of the items.
Tags
Grid
Asked by
Ahrensberg
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Ahrensberg
Top achievements
Rank 1
Iana Tsolova
Telerik team
Share this question
or