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

RadComboBox inside RadGrid CommandItem

4 Answers 209 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Baal
Top achievements
Rank 1
Baal asked on 15 Jul 2008, 08:46 PM
I have a RadGrid. Inside the CommandItemTemplate, I have a RadComboBox. What I am trying to do is when I select the different items in the RadComboBox, there is a RadToolTip that displays the information about the selected item. For ths I needed to do a postback with the SelectedIndexChanged event of the RadComboBox. Problem is when I select an item, the RadComboBox disappears.

Here is what I have for the RadGrid.
<rad:RadGrid ID="rgCustomer" runat="server"  AllowPaging="true" AllowSorting="true" AutoGenerateColumns="false"  
    OnItemCreated="rgCustomer_ItemCreated" OnItemCommand="rgCustomer_ItemCommand" Skin="Telerik" DataSourceID="odsCustomer"
         
    <PagerStyle Mode="NextPrevAndNumeric" /> 
     
    <ClientSettings EnableRowHoverStyle="true"
        <Selecting AllowRowSelect="true" /> 
    </ClientSettings> 
         
    <MasterTableView Width="100%" ShowFooter="false" DataKeyNames="CustomerId" CommandItemDisplay="Top"
         
        <CommandItemTemplate> 
            <div style="width:100%; margin:5px 5px 5px 5px;"
                     
                <div style="width:10%; float:left; vertical-align:top; text-align:center;"
                    Customer: 
                </div> 
                <div style="width:40%; float:left; vertical-align:top; text-align:center;"
                    <div style="width:100%; text-align:center;"
                        <rad:RadComboBox ID="rcbLocation" runat="server" Width="400px" Height="300px" MarkFirstMatch="true"  
                            EnableLoadOnDemand="true" Skin="Telerik" AutoPostBack="true" OnSelectedIndexChanged="rcbLocation_SelectedIndexChanged" />                
                              
                        <asp:RequiredFieldValidator ID="rfvLocation" runat="server" ControlToValidate="rcbLocation" Display="Dynamic"  
                            SetFocusOnError="true" EnableClientScript="true" ErrorMessage="Required" InitialValue="0" ValidationGroup="save" /> 
                                     
                        <rad:RadToolTip ID="rttLocation" runat="server" TargetControlID="rcbLocation" Sticky="true" Animation="Fade"  
                            Position="MiddleRight" RelativeTo="Element" Skin="Telerik"
                            <asp:Label ID="lblRttLocation" runat="server" /> 
                        </rad:RadToolTip> 
                    </div> 
                </div> 
                <div style="width:40%; float:left; vertical-align:top; text-align:center;"
                    <rad:RadTextBox" ID="rtbCustomer" runat="server" Width="400px" Skin="Telerik" /> 
                    <asp:RequiredFieldValidator ID="rfvCustomer" runat="server" ControlToVaidate"="rtbCustomer" Display="Dynamic"  
                        SetFocusOnError="true" EnableClientScript="true" ErrorMessage="Required" ValidationGroup="save" /> 
                </div> 
                <div style="width:10%; float:left; vertical-align:top; text-align:center;"
                    <asp:Button ID="btnAdd" runat="server" Text="Add" OnClick="btnAdd_Click" ValidationGroup="save" /> 
                </div> 
                     
            </div> 
                     
        </CommandItemTemplate> 
                 
        <Columns> 
         
            <rad:GridBoundColumn HeaderText="Id" DataField="CustomerId" SortExpression="CustomerId" /> 
                 
            <rad:GridBoundColumn HeaderText="Location" DataField="Location" SortExpresstion="Location" /> 
             
            <rad:GridBoundColumn HeaderText="Name" DataField="CustomerName" SortExpresstion="CustomerName" /> 
             
        </Columns> 
         
    </MasterTableView> 
     
</rad:RadGrid> 

On the codebehind, I have
private Table gTable; 
private GridTHead gHead; 
private GridCommandItem gItem; 
 
protected void Page_Load(object sender, EventArgs e) 
    if (!IsPostBack) 
    { 
        rgCustomer.DataBind(); 
 
        gTable = (Table)rgCustomer.MasterTableView.Controls[0]; 
        gHead = (GridTHead)gTable.Controls[0]; 
        gItem = (GridCommandItem)gHead.Controls[0]; 
 
        RadComboBox rcb = (RadComboBox)gItem.FindControl("rcbLocation"); 
        rcb.Items.Clear(); 
 
        rcb.DataSource = LocationList.Search(null, null, null, null, null, null, null, null, null); 
        rcb.DataTextField = "LocationName"
        rcb.DataValueField = "LocationId"
        rcb.DataBind(); 
        rcb.Items.Insert(0, new RadComboBoxItem("Select", "0")); 
    } 
 
 
protected void rcbLocation_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e) 
    Label lbl = (Label)gItem.FindControl("lblRttLocation"); 
    if (e.Value == "0") 
        lbl.Text = "Select a Location"
    else 
    { 
        LocationList oLocation = LocationList.Get(Convert.ToInt32(e.Value)); 
        lbl.Text = LocationList.LocationDetails; 
        oLocation = null
    } 

When the page loads, I can see the Location RadComboBox in the CommandItem. It has all the items loaded in it. But when I select an item in it, the ComboBox control disappears (only the combobox, other controls are fine.. I do have a RadAjaxManager whose initiate ControlId is RadGrid and update ControlId is itself.

Thank you.

4 Answers, 1 is accepted

Sort by
0
Yavor
Telerik team
answered on 16 Jul 2008, 12:03 PM
Hi Baal,

Using simple databinding in this scenario for the grid, is not recommended. Please, consider using AdvancedDatabinding.

Best wishes,
Yavor
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Princy
Top achievements
Rank 2
answered on 16 Jul 2008, 12:24 PM
Hi Baal,

You can also go through the online demo regarding AdvanceDataBinding techniques.
Advanced data-binding

Thanks
Princy
0
Baal
Top achievements
Rank 1
answered on 16 Jul 2008, 02:18 PM
I think you guys understood it wrong. I do not have problem binding data to the grid. My problem is when I select a new item in the combobox, which is in the commanditem of the grid, the combobox disappears. Just wondering why that is happening.
0
Baal
Top achievements
Rank 1
answered on 16 Jul 2008, 05:31 PM
Don't worry, it is fixed now. I added the following
gTable = (Table)rgCustomer.MasterTableView.Controls[0];  
gHead = (GridTHead)gTable.Controls[0];  
gItem = (GridCommandItem)gHead.Controls[0];  

in the else condition of if(!IsPostback) and it worked beautifully.

Thanks.


Tags
Grid
Asked by
Baal
Top achievements
Rank 1
Answers by
Yavor
Telerik team
Princy
Top achievements
Rank 2
Baal
Top achievements
Rank 1
Share this question
or