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
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;
}
//--------------------------------------------------------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;
}