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

Rad Grid & Rad Combo

14 Answers 215 Views
Grid
This is a migrated thread and some comments may be shown as answers.
kollam2003
Top achievements
Rank 1
kollam2003 asked on 24 Mar 2009, 12:05 PM
Hai,
I Have two rad combo boxes in a rad grid.
In the first rad combos selected index changed the values are to be filled in the second one.
How can I accomplish this?
I'm using the inline editing method.

Deepak S

14 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 1
answered on 24 Mar 2009, 12:30 PM
Hi Deepak,

Here is an online demo which implements the requested functionality in edit mode. You can use a similar logic.
Accessing Cells and Rows

Shinu
0
kollam2003
Top achievements
Rank 1
answered on 25 Mar 2009, 04:29 AM
But I 'm having the two comboboxes in two template columns of the grid.
The "Autopostback" property of the first combo is set to true, & OnSelectedIndexChanged is called.
But the event is nt fired.
Plz Help

0
Shinu
Top achievements
Rank 1
answered on 25 Mar 2009, 07:39 AM
Hi Deepak,

Can you send your aspx code and code behind.

Shinu
0
kollam2003
Top achievements
Rank 1
answered on 25 Mar 2009, 08:34 AM
Hi Shinu,

Code:

 
 <telerik:GridTemplateColumn HeaderText="State" SortExpression="StateName" DataField="StateName" 
                                                 UniqueName="StateName" > 
                                   <EditItemTemplate> 
                                     <sup>*</sup><telerik:RadComboBox ID="RadComboBox_StateName" Runat="server" Skin="Inox" MarkFirstMatch="True" Font-Names="Arial" AutoPostBack="true" OnSelectedIndexChanged="RadComboBox_StateName_SelectedIndexChanged" > 
                                            <Items> 
                                                <telerik:RadComboBoxItem runat="server" Text="---Select---"  
                                                    Value="---Select---" /> 
                                            </Items> 
                                            <CollapseAnimation Duration="200" Type="OutQuint" /> 
                                        </telerik:RadComboBox> 
                                      <asp:RequiredFieldValidator ID="RFV_StateName"  runat="server" ControlToValidate="RadComboBox_StateName" Display="None" ErrorMessage="Please select State" SetFocusOnError="True" InitialValue="---Select---"
                                      </asp:RequiredFieldValidator> 
                                       <cc1:ValidatorCalloutExtender ID="VCE_StateName" runat="server" TargetControlID="RFV_StateName"
                                       </cc1:ValidatorCalloutExtender> 
                                         <asp:Label ID="lblStateID" runat="server" Visible="false" Text='<%# DataBinder.Eval(Container.DataItem, "SchoolState")%>'></asp:Label> 
                                    </EditItemTemplate> 
                                    <ItemTemplate> 
                                     <asp:Label ID="lblStateName" runat="server" Text='<%# Eval("StateName")%>'></asp:Label> 
                                    </ItemTemplate> 
                                    <HeaderStyle Font-Bold="True" ForeColor="#192666"></HeaderStyle> 
                                    </telerik:GridTemplateColumn> 
                                     
                                    <telerik:GridTemplateColumn UniqueName="CityName" HeaderText="City" 
                                        DataField="CityName" SortExpression="CityName" Visible="false"
                                        <ItemTemplate> 
                                            <asp:Label ID="lblCityName" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "CityName")%>'
                                
                                            </asp:Label> 
                                        </ItemTemplate> 
                                        <EditItemTemplate> 
                                     <sup>*</sup><telerik:RadComboBox ID="RadComboBox_CityName" Runat="server" Skin="Inox" MarkFirstMatch="True" Font-Names="Arial"
                                            <Items> 
                                                <telerik:RadComboBoxItem runat="server" Text="---Select---"  
                                                    Value="---Select---" /> 
                                            </Items> 
                                            <CollapseAnimation Duration="200" Type="OutQuint" /> 
                                        </telerik:RadComboBox> 
                                      <asp:RequiredFieldValidator ID="RFV_CityName"  runat="server" ControlToValidate="RadComboBox_CityName" Display="None" ErrorMessage="Please select City" SetFocusOnError="True" InitialValue="---Select---"
                                      </asp:RequiredFieldValidator> 
                                       <cc1:ValidatorCalloutExtender ID="VCE_CityName" runat="server" TargetControlID="RFV_CityName"
                                       </cc1:ValidatorCalloutExtender> 
                                         <asp:Label ID="lblCityID" runat="server" Visible="false" Text='<%# DataBinder.Eval(Container.DataItem, "SchoolCity")%>'></asp:Label> 
                                    </EditItemTemplate> 
                                        <HeaderStyle ForeColor="#192666" Font-Bold="True" /> 
                                    </telerik:GridTemplateColumn> 
 public void RadComboBox_StateName_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e) 
    { 
        //first reference the edited grid item through the NamingContainer attribute 
        GridEditableItem editedItem = (sender as RadComboBox).NamingContainer as GridEditableItem; 
 
        
        RadComboBox RadComboBox_CityName = (editedItem.FindControl("RadComboBox_CityName") as RadComboBox); 
        //Bind City 
        DataTable _dtCity = new DataTable(); 
        _dtCity.Clear(); 
        RadComboBox_CityName.Items.Clear(); 
        _dtCity = objSetup.Setup_Bind_RadGrid_City(); 
        if (_dtCity.Rows.Count > 0) 
        { 
            if (_dtCity.Rows.Count > 15) 
            { 
                RadComboBox_CityName.Height = 410
            } 
            foreach (DataRow dr in _dtCity.Rows) 
            { 
                RadComboBoxItem items = new RadComboBoxItem(dr["CityName"].ToString(), dr["CityID"].ToString()); 
                RadComboBox_CityName.Items.Add(items); 
 
            } 
            RadComboBox_CityName.Items.Insert(0, new RadComboBoxItem("---Select---")); 
        } 
        else 
        { 
            RadComboBox_CityName.Items.Insert(0, new RadComboBoxItem("---Select---")); 
        } 
       
 
    } 



0
Princy
Top achievements
Rank 1
answered on 25 Mar 2009, 09:37 AM
Hi Deepak,

Your code seems to be correct and I cant find out a reason why the SelectedIndexChanged event does not fire at your end. I tried something similar at my end and it works as expected:
aspx:
<telerik:GridTemplateColumn UniqueName="TemplateColumn11"
    <ItemTemplate> 
           <telerik:RadComboBox ID="RadComboBox1" AutoPostBack="true" DataSourceID="SqlDataSource1" DataTextField="Title" DataValueField="Title" runat="server" OnSelectedIndexChanged="RadComboBox1_SelectedIndexChanged"
           </telerik:RadComboBox>              
    </ItemTemplate> 
</telerik:GridTemplateColumn> 

cs:
 protected void RadComboBox1_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e) 
    { 
 
    } 

Thanks
Princy.
0
kollam2003
Top achievements
Rank 1
answered on 25 Mar 2009, 10:07 AM
Hi,
Still my combos selected index changed event is nt fired.
Should i change any other settings for the grid ?
0
Shinu
Top achievements
Rank 1
answered on 25 Mar 2009, 10:17 AM
Hi Deepak,

Setting the AutoPostBack property of the DropDownList must fire the SelectedIndexChanged event. If this is not working I would suggest you to use GridDropDownColumn instead of GridTemplateColumn as shown in the online demo here.
http://demos.telerik.com/aspnet-ajax/grid/examples/programming/accessingcellsandrows/defaultcs.aspx

Shinu
0
kollam2003
Top achievements
Rank 1
answered on 25 Mar 2009, 01:02 PM
But this method is not suitable for me.
If I want to add a '*' mark in front of the combo what should I do?
0
Shinu
Top achievements
Rank 1
answered on 26 Mar 2009, 07:16 AM
Hi Deepak,

Try with the following approach and see if it helps.

ASPX:
 
<telerik:GridDropDownColumn UniqueName="DropCol" DataField="ProductName" DataSourceID="SqlDataSource1" ListValueField="ProductName"  ListTextField="ProductName" ></telerik:GridDropDownColumn> 
                 

CS:
 
 
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) 
    { 
        if((e.Item is GridEditableItem )&&(e.Item.IsInEditMode)) 
        { 
            GridEditableItem editItem = (GridEditableItem)e.Item; 
            Literal lit = new Literal(); 
            lit.Text = "*"
            editItem["DropCol"].Controls.Add(lit); 
             
        } 
    } 

Thanks
Shinu



0
kollam2003
Top achievements
Rank 1
answered on 27 Mar 2009, 04:33 AM
Hi,
Thank you Shinu.
One more thing I want dat literal to be in the left side of the dropdown.
How to do it?

Deepak S
0
kollam2003
Top achievements
Rank 1
answered on 27 Mar 2009, 04:48 AM
Also can we validate this using required field validator?
0
kollam2003
Top achievements
Rank 1
answered on 27 Mar 2009, 05:18 AM
I did with the GridDropDownColumn, bt same is the case, in the "Add New Record"  the selected index of the first drop down is nt working.
This was the case when i was working with the template columns.
plz help

0
kollam2003
Top achievements
Rank 1
answered on 28 Mar 2009, 03:51 AM

Hai

I did with the GridDropDownColumn, bt same is the case, in the "Add New Record"  the selected index of the first drop down is nt working.
This was the case when i was working with the template columns.
plz help
0
kollam2003
Top achievements
Rank 1
answered on 31 Mar 2009, 12:39 PM
I was using required field validators for the two combo boxes - state & city.
When I removed the required field validator of the City its working fine.
But I want the City also a required field.
What should I do?
Plz Help
Tags
Grid
Asked by
kollam2003
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
kollam2003
Top achievements
Rank 1
Princy
Top achievements
Rank 1
Share this question
or