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

[Solved] Using dropdownlist in radgrid:(error) Cannot find Column Id

1 Answer 181 Views
Grid
This is a migrated thread and some comments may be shown as answers.
vishesh kumar
Top achievements
Rank 1
vishesh kumar asked on 08 Feb 2010, 03:26 AM
Hi,
i am trying to use a dropdownlist(separate data source) inside a radgrid. While binding the radgrid to the datasource i get this exception:
Exception Details: System.IndexOutOfRangeException: Cannot find column Id.
here is the code that i am using the ascx file

<telerik:RadGrid ID="radGridApplicantStatus" runat="server" AllowSorting="true" AllowPaging="true" 
                PageSize="12" AllowMultiRowSelection="false" ShowGroupPanel="true" GridLines="None" 
                OnNeedDataSource="OnRadGridApplicantStatus_NeedSource" OnSortCommand="OnRadGridApplicantStatus_SortCommand" 
                OnItemDataBound="OnRadGridApplicantStatus_ItemDataBound"
                <PagerStyle Mode="NumericPages" AlwaysVisible="true" Position="Bottom" /> 
                <MasterTableView AutoGenerateColumns="false" EnableNoRecordsTemplate="true" ShowHeadersWhenNoRecords="true" 
                    AllowNaturalSort="false"
                    <SortExpressions> 
                        <telerik:GridSortExpression FieldName="Id" SortOrder="Descending" /> 
                    </SortExpressions> 
                    <NoRecordsTemplate> 
                        Jobs 
                    </NoRecordsTemplate> 
                    <Columns> 
                        <telerik:GridBoundColumn UniqueName="JobID" SortExpression="JobID" HeaderText="Order #" 
                            DataField="JobID" HeaderStyle-CssClass="ms-toolbar" HeaderStyle-Width="17%" HeaderStyle-HorizontalAlign="Left" 
                            ItemStyle-HorizontalAlign="Left" ItemStyle-Wrap="false"
                        </telerik:GridBoundColumn> 
                        <telerik:GridBoundColumn UniqueName="JobTitle" SortExpression="JobTitle" HeaderText="Title" 
                            DataField="JobTitle" HeaderStyle-CssClass="ms-toolbar" HeaderStyle-Width="12%" 
                            HeaderStyle-HorizontalAlign="Left" ItemStyle-HorizontalAlign="Left" ItemStyle-Wrap="false"
                        </telerik:GridBoundColumn> 
                         
                      <telerik:GridTemplateColumn UniqueName="ApplicantStatus" SortExpression="ApplicantStatus" 
                            HeaderText="Applicant Status" DataField="ApplicantStatus" HeaderStyle-CssClass="ms-toolbar" 
                            HeaderStyle-Width="12%" HeaderStyle-HorizontalAlign="Left" ItemStyle-HorizontalAlign="Left" 
                            ItemStyle-Wrap="false"
                            <ItemTemplate> 
                                <asp:DropDownList runat="server" ID="ddlApplicationStatus"
                                </asp:DropDownList> 
                            </ItemTemplate> 
                        </telerik:GridTemplateColumn> 
                    </Columns> 
                </MasterTableView> 
            </telerik:RadGrid> 



Questions:
1. Should i use this gridtemplatecolumn or a GridDropDownColumn? I need to show a dropdown box in the grid which is in non -Editable mode.
2. How to fix this error?

1 Answer, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 08 Feb 2010, 06:38 AM
Hello Vishesh Kumar,

From your code, I can see that you have set FieldName as "Id" for the GridSortExpression. The FieldName should be the name of a single field from the data source. Please make sure that "Id" is field in data source.

And you can try the following code, if you want to access the dropdownlist from code and to populate it.

CS:
 
    protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) 
    { 
        if (e.Item is GridDataItem) 
        { 
            GridDataItem item = (GridDataItem)e.Item; 
            DropDownList dropdown = (DropDownList)item.FindControl("ddlApplicationStatus"); 
            // Populate the dropdown 
        } 
    } 

ASPX:
 
<telerik:GridTemplateColumn UniqueName="ApplicantStatus"   HeaderText="Applicant Status"
    <ItemTemplate> 
        <asp:DropDownList runat="server" ID="ddlApplicationStatus"
        </asp:DropDownList> 
    </ItemTemplate> 
</telerik:GridTemplateColumn> 

-Shinu.
Tags
Grid
Asked by
vishesh kumar
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or