This is a migrated thread and some comments may be shown as answers.
RadGrid FilterByColumn
2 Answers 26 Views
This is a migrated thread and some comments may be shown as answers.
Robert Jakech
Top achievements
Rank 1
Robert Jakech asked on 23 May 2010, 02:24 PM
I have a radgrid created as below:
//--------------------------------------------------------ASPX---------------------------------------
 <telerik:RadGrid id="deadmitStudents" runat="server" AllowFilteringByColumn="true" Width="100%"  
     AutoGenerateColumns="false" PageSize="30" AllowPaging="true" OnNeedDataSource="OnNeedDataSource_AdmittedStudents">
    <MasterTableView DataKeyNames="IndexNumber" CommandItemDisplay="Top" TableLayout="Auto" AllowFilteringByColumn="True" FilterItemStyle-Wrap="true" FilterItemStyle-Width="40px">
                        <Columns>
                        <telerik:GridTemplateColumn AllowFiltering="True"  Resizable="true" UniqueName="IndexNumber" HeaderText="Index Number">
                                <ItemTemplate>
                                <asp:Label ID="indexNumberLabel" runat="server" Text='<% #Bind("IndexNumber") %>' ForeColor="Black" Font-Size="Medium"></asp:Label>
                                </ItemTemplate>
                                 </telerik:GridTemplateColumn>
                            <telerik:GridTemplateColumn AllowFiltering="True" Resizable="true" UniqueName="FullName" HeaderText="Full Name">
                                <ItemTemplate>
                                <asp:Label ID="fullnameLabel" runat="server" ForeColor="Black" Font-Size="Medium" Text='<% #Bind("FullName") %>'></asp:Label>
                                </ItemTemplate>
                                 </telerik:GridTemplateColumn>
                       <telerik:GridTemplateColumn AllowFiltering="False"  UniqueName="deAdmit" HeaderText="DeAdmit">
                            <ItemTemplate>
                            <asp:CheckBox ID="chkDeadmit" runat="server" />
                                </ItemTemplate>
                                 </telerik:GridTemplateColumn>
                    </Columns>
                     </MasterTableView>
    </telerik:RadGrid>
All I want is to have a simple Filtering on some columns as created in the RadGrid. When executed, i get the following error message

is neither a DataColumn nor a DataRelation for table .

Please kindly help.
Check my code behind below:
//--------------------------------------------------------CODE BEHIND---------------------------------------
    protected void OnNeedDataSource_AdmittedStudents(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
        {
            try
            {
                deadmitStudents.DataSource = getAdmittedStudents(RadComboBoxCampus.SelectedValue, int.Parse(RadComboBoxIntake.SelectedValue),
                    RadComboBoxAcademicYear.SelectedValue, int.Parse(RadComboBoxStudyTime.SelectedValue));
            }
            catch
            {
            }
        }
          protected DataTable getAdmittedStudents(string campus,int intake, string academicYear, int studyTime)
        {
            SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["Main.ConnectionString"]);
            string query = "select StudentId,IndexNumber,(coalesce(SurName,'') + ' ' + coalesce(OtherNames,'')) as fullname, ProgrammeName as Programme,Intake,EnrollmentType, " +
           "AcademicYr,Campus from GeneralStudentInfo where Intake='" + intake + "'" +
           "and AcademicYr='" + academicYear + "' and Campus='" + campus + "' and EnrollmentType='" + studyTime + "'";
            //SqlConnection conn = new SqlConnection(ConnString);

            conn.Open();
            SqlCommand cmd = new SqlCommand(query,conn);
            SqlDataAdapter adapter = new SqlDataAdapter(cmd);
            DataTable myDataTable = new DataTable();
            try
            {
                adapter.Fill(myDataTable);
            }
            finally
            {
                conn.Close();
            }
            return myDataTable;

        }
       


2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 1
answered on 24 May 2010, 06:27 AM
Hello Robert,

You need to set the DataField property of GridTemplateColumn in order to allow filter.

ASPX:
  <telerik:GridTemplateColumn AllowFiltering="True" Resizable="true" UniqueName="IndexNumber" 
                        DataField="IndexNumber" HeaderText="IndexNumber"
               <ItemTemplate> 
                            <asp:Label ID="indexNumberLabel" runat="server" Text='<% #Bind("IndexNumber") %>' 
                                ForeColor="Black" Font-Size="Medium"></asp:Label> 
              </ItemTemplate> 
  </telerik:GridTemplateColumn> 

Regards,
Shinu.
0
Robert Jakech
Top achievements
Rank 1
answered on 24 May 2010, 07:10 AM
Shinu, you are the best!

I appreciate.

Thankss.
Tags
Grid
Asked by
Robert Jakech
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
Robert Jakech
Top achievements
Rank 1
Share this question
or