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

Limit Contents of Combobox in RadGrid

3 Answers 91 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Steve Humby
Top achievements
Rank 1
Steve Humby asked on 18 Dec 2008, 02:23 PM
Hi all

Having a bit of a dilemma, does anyone know how to do the following:

I've bound an SqlDataSource to a RadGrid which displays various data but typically an AreaID and an InterviewerID amongst many. When in EditMode, the only thing that I want to edit is the InterviewerID, so I have added a ComboBox in the EditItemTemplate and a label in the ItemTemplate.

My ComboBox is populated by another SqlDataSource containing ALL Interviewers but also holds a value for the AreaID (such as InterviewerID, Interviewer, AreaID).

What I would like to do is pick up the AreaID from the row currently being edited and limit the contents of the Combo to only Interviewers in that Area.

There must be a simple way of doing it but I'ts not making itself obvious to me - can anyone help please?

Thanks in anticipation.

Steve :o)

3 Answers, 1 is accepted

Sort by
0
Iana Tsolova
Telerik team
answered on 20 Dec 2008, 02:11 PM
Hi Steve,

The declarative and easiest way to achieve your purpose is to declare the SqlDataSource control within the EditTemplate where the combo is and set the parameter value as shown below:

<telerik:GridTemplateColumn UniqueName="TemplateColumn" HeaderText="Interviewer" 
    SortExpression="InterviewerID" DataField="InterviewerID">  
    <ItemTemplate> 
        <%#DataBinder.Eval(Container.DataItem,"InterviewerID")%> 
    </ItemTemplate> 
    <EditItemTemplate> 
        <asp:Label ID="Label1" Text='<%# Eval("InterviewerID") %>' Visible="false" runat="server" /> 
        <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>" 
            SelectCommand="<your select command here>">  
            <SelectParameters> 
                <asp:ControlParameter ControlID="Label1" PropertyName="Text" Type="String" Name="AreaID" /> 
            </SelectParameters> 
        </asp:SqlDataSource> 
        <telerik:RadComboBox DataTextField="InterviewerID" DataValueField="InterviewerID" ID="RadComboBox1" 
            runat="server" SelectedValue='<%#Bind("InterviewerID") %>' 
            DataSourceID="SqlDataSource2">  
        </telerik:RadComboBox>                                  
    </EditItemTemplate> 
</telerik:GridTemplateColumn> 

Another approach is to handle the ItemDataBound event of the grid and set the combobox data source there as described here.

Give it a try and let me know if this helps.

Greetings,
Iana
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
The Wire
Top achievements
Rank 1
answered on 19 Apr 2010, 08:23 PM
I am using the "declarative, easiest" way described by declaring the SqlDataSource inside the EditItemTemplate.  However I am getting this error: "The DataSourceID of 'ddlPhase' must be the ID of a control of type IDataSource.  A control with ID 'dsPhase' could not be found."

If I pull the SqlDataSource out of the RadGrid, the error goes away, which I'm assuming means the control was found, but then my combobox is empty.  Here is my code:

    <rad:RadGrid ID="gvGrid1" runat="server" AutoGenerateColumns="false" DataSourceID="dsGrid1">   
        <MasterTableView DataSourceID="dsGrid1" DataKeyNames="Company_Code,Code" CellPadding="0" CellSpacing="0" EditMode="InPlace">  
            <Columns> 
        ...  
            </Columns> 
            <DetailTables> 
                <rad:GridTableView TableLayout="Auto" DataKeyNames="ID,Company_Code,Code" DataSourceID="dsGrid1a" runat="server" Width="100%" EditMode="InPlace">  
                    <ParentTableRelation> 
                        <rad:GridRelationFields DetailKeyField="Company_Code" MasterKeyField="Company_Code" /> 
                        <rad:GridRelationFields DetailKeyField="Code" MasterKeyField="Code" /> 
                    </ParentTableRelation> 
                    <Columns> 
                        <rad:GridEditCommandColumn ButtonType="LinkButton" EditText="Edit" /> 
                        <rad:GridTemplateColumn HeaderText="Phase" HeaderStyle-Width="125" ItemStyle-HorizontalAlign="Left">  
                            <ItemTemplate><%# Eval("Phase") %></ItemTemplate>  
                            <EditItemTemplate> 
                                <asp:Label ID="lblCompany_Code" runat="server" Text='<%# Eval("Company_Code") %>' /> 
                                <asp:Label ID="lblCode" runat="server" Text='<%# Eval("Code") %>' /> 
                                <rad:RadComboBox ID="ddlPhase" runat="server" Width="100" 
                                    DataSourceID="dsPhase" DataTextField="Phase" DataValueField="Phase_Code"></rad:RadComboBox> 
                                <asp:SqlDataSource ID="dsPhase" runat="server" 
                                    ConnectionString="<%$ ConnectionStrings:CustomApplicationPages.Properties.Settings.MYCONNECTION %>" 
                                    SelectCommand="dsPhase_Select_SP" SelectCommandType="StoredProcedure">  
                                    <SelectParameters> 
                                        <asp:ControlParameter ControlID="lblCompany_Code" PropertyName="Text" Name="Company_Code" /> 
                                        <asp:ControlParameter ControlID="lblCode" PropertyName="Text" Name="Code" /> 
                                    </SelectParameters> 
                                </asp:SqlDataSource> 
                            </EditItemTemplate> 
                        </rad:GridTemplateColumn> 
                        ...other columns...  
                    </Columns> 
                </rad:GridTableView> 
            </DetailTables> 
        </MasterTableView> 
    </rad:RadGrid> 
    <asp:SqlDataSource ID="dsGrid1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:CustomApplicationPages.Properties.Settings.MYCONNECTION %>" 
        SelectCommand="dsGrid1_Select_SP" SelectCommandType="StoredProcedure">  
    </asp:SqlDataSource> 
    <asp:SqlDataSource ID="dsGrid1a" runat="server" 
        ConnectionString="<%$ ConnectionStrings:CustomApplicationPages.Properties.Settings.MYCONNECTION %>" 
        SelectCommand="dsGrid1a_Select_SP" SelectCommandType="StoredProcedure">  
        <SelectParameters> 
            <asp:Parameter Name="Company_Code" /> 
            <asp:Parameter Name="Code" /> 
        </SelectParameters> 
    </asp:SqlDataSource> 

How can I bind the ComboBox using two parameters from the respective row of the GridTableView?
0
The Wire
Top achievements
Rank 1
answered on 20 Apr 2010, 03:10 PM
Nevermind, turns out the SqlDataSource needs to come BEFORE the combobox on the page, just like in Iana's example.  Just an overlooked detail on my part.

Thanks.
Tags
Grid
Asked by
Steve Humby
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
The Wire
Top achievements
Rank 1
Share this question
or