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

How i get Radcombobox ControlID in RadGrid

7 Answers 137 Views
Grid
This is a migrated thread and some comments may be shown as answers.
kerim
Top achievements
Rank 1
kerim asked on 25 Jun 2010, 05:14 PM


<telerik:GridTemplateColumn DataField="City" HeaderText="City" UniqueName="City">  
<EditItemTemplate> 
<telerik:RadComboBox ID="CB_City"  AppendDataBoundItems="true" Height="100px" runat="server" Skin="Black" 
DataTextField="CityName" DataValueField="CityName" DataSourceID="SqlDataSourceCity"  
SelectedValue='<%# Bind("City")%>' AutoPostBack="true">  
</telerik:RadComboBox> 
</EditItemTemplate> 
<ItemTemplate> 
<%# Eval("City")%> 
</ItemTemplate> 
</telerik:GridTemplateColumn>

		
<
asp:SqlDataSource
ID
="SqlDataSourceTown"
runat="server"
ConnectionString="<%$ ConnectionStrings:connectionString %>"
ProviderName
="System.Data.SqlClient"
SelectCommand
="sp_town_list"
SelectCommandType="StoredProcedure">
<SelectParameters>
     <asp:ControlParameter   
ControlID="??????????????????"     <<<<<<<< CB_City ControlID Doesnt work :((
DefaultValue="New York"   
Name="CityName" 
PropertyName="SelectedValue"   
Type="String" />
</SelectParameters>




7 Answers, 1 is accepted

Sort by
0
Casey
Top achievements
Rank 1
answered on 25 Jun 2010, 06:45 PM
I'm not sure if this is a viable option for you or not, but have you tried adding the parameter in the SelectedIndexChanged event of the RadComboBox?

protected void CB_City_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e) 
    { 
        SqlDataSourceTown.SelectParameters.Clear(); 
        SqlDataSourceTown.SelectParameters.Add("CityName", e.Value); 
    } 

0
kerim
Top achievements
Rank 1
answered on 26 Jun 2010, 08:17 AM
but i cant see any radcombobox event in code behind ... only RadGrid1 events..

i try your code,  i do not get an error but not working ..  :((
0
Casey
Top achievements
Rank 1
answered on 28 Jun 2010, 01:21 PM
Did you add "OnSelectedIndexChanged="CB_City_SelectedIndexChanged" in the properties of the RadComboBox in the GridTemplateColumn?
0
kerim
Top achievements
Rank 1
answered on 29 Jun 2010, 08:12 AM
ok its work .I couldnt do what I want .. i want to ; when combo1 selected .. post back , combo2 refresh and got a new data with combo1 as filter. i can do it in normal form with radcombo box.. but i cant use radcombobox as control parameter in datagrid ... i cant use control id ..

ex Grid what i want:

Name    RadTextbox
Country    RadComboBox  
City   RadComboBox
Town    RadComboBox
Age
....
....


0
Casey
Top achievements
Rank 1
answered on 29 Jun 2010, 01:20 PM
Could you try something like the below and see if you are able to find the other control? I'm not sure how you are handling assigning datasources to  your RadComboBoxes, but you can add the value they selected from the Country combobox to your parameter before assigning it to the State combobox by using e.Value.

I hope this helps!

<telerik:GridTemplateColumn UniqueName="Country" HeaderText="Country"
   <ItemTemplate> 
       <telerik:RadComboBox ID="rcbCountry" runat="server"
                        OnSelectedIndexChanged="rcbCountry_SelectedIndexChanged" 
                            AutoPostBack="true">  
       </telerik:RadComboBox>  
   </ItemTemplate> 
</telerik:GridTemplateColumn> 
<telerik:GridTemplateColumn UniqueName="STATE" HeaderText="State"
   <ItemTemplate> 
       <telerik:RadComboBox ID="rcbSTATE" runat="server"
                        OnSelectedIndexChanged="rcbSTATE_SelectedIndexChanged" 
                            AutoPostBack="true">  
       </telerik:RadComboBox>  
   </ItemTemplate> 
</telerik:GridTemplateColumn> 


protected void rcbCountry_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)  
    {  
        var combo = (RadComboBox)o;  
        var gridItem = combo.NamingContainer as GridDataItem;  
         
          
        ((RadComboBox)gridItem["STATE"].FindControl("rcbSTATE")).DataSourceID = "YourNewDataSource"   
    }  

0
Casey
Top achievements
Rank 1
answered on 29 Jun 2010, 02:05 PM
I remembered that you are trying to use a SQL datasource and want to get the control ID for the <asp:ControlParameter>. If you replace the <asp:ControlParameter> with just an <asp:Parameter>, you can do the following in the SelectedIndexChanged Event:

protected void rcbCountry_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)   
    {   
        var combo = (RadComboBox)o;   
        var gridItem = combo.NamingContainer as GridDataItem;   
          
        SqlDataSourceState.SelectParameters.Clear(); 
        SqlDataSourceState.SelectParameters.Add("CountryName", e.Value.ToString());   
 
        ((RadComboBox)gridItem["STATE"].FindControl("rcbSTATE")).DataSourceID = "SqlDataSourceState";    
    }   

0
kerim
Top achievements
Rank 1
answered on 30 Jun 2010, 08:29 AM
thank you so much casey
but i had tried this...  i can set combo's datasource...   I still did'nt want ..  because until mastertableview databind , combo's data not loaded.. radcombo databind not working.. ... so  ... when mastertableview databind , all controls are cleared....

i design new form out radgrid and solve my problem..

thanx again..
Tags
Grid
Asked by
kerim
Top achievements
Rank 1
Answers by
Casey
Top achievements
Rank 1
kerim
Top achievements
Rank 1
Share this question
or