Hi,
I am trying to have Grid in Rad Combo Box. I am able to show grid in Combo Box but what i want to do is user should be able to filter items using grid filters. Only when he clicks on some row in grid then the information in that grid should be displayed in Combo box, the id which is hidden for any column should be accessible from Code behind.
Following is sample code that i am using.
Aspx Page
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div>
<telerik:radcombobox id="RadComboBox1" runat="server" skin="Office2007" width="100%"
nowrap="True">
<ItemTemplate>
<div>
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="False" GridLines="None"
AllowFilteringByColumn="True" AllowPaging="True" AllowSorting="True" OnNeedDataSource="RadGrid1_NeedDataSource"
EnableLinqExpressions="false" PageSize="100">
<MasterTableView AllowFilteringByColumn="true">
<RowIndicatorColumn>
<HeaderStyle Width="20px"></HeaderStyle>
</RowIndicatorColumn>
<ExpandCollapseColumn>
<HeaderStyle Width="20px"></HeaderStyle>
</ExpandCollapseColumn>
<Columns>
<telerik:GridBoundColumn DataField="Name" HeaderText="Name" SortExpression="Name"
UniqueName="Name" CurrentFilterFunction="Contains" AutoPostBackOnFilter="false"
Display="false">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Subject1" HeaderText="Subject" SortExpression="Subject1"
UniqueName="Subject1" CurrentFilterFunction="StartsWith" AutoPostBackOnFilter="false"
Display="false">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="RollNumber" HeaderText="Roll Number" SortExpression="RollNumber"
UniqueName="RollNumber" CurrentFilterFunction="GreaterThan" AutoPostBackOnFilter="false">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Score" HeaderText="Score" SortExpression="Score"
UniqueName="Score" CurrentFilterFunction="EqualTo" AutoPostBackOnFilter="false">
</telerik:GridBoundColumn>
</Columns>
</MasterTableView>
<ClientSettings AllowColumnsReorder="True" ReorderColumnsOnClient="True" AllowColumnHide="True">
<Scrolling AllowScroll="True" UseStaticHeaders="True" />
<Resizing AllowColumnResize="True" EnableRealTimeResize="True" ResizeGridOnColumnResize="True" />
</ClientSettings>
</telerik:RadGrid>
</div>
</ItemTemplate>
<Items>
<telerik:RadComboBoxItem />
</Items>
<CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation>
</telerik:radcombobox>
</div>
</form>
</body>
</html>
Code Behind
using System;
using System.Web.UI;
using Telerik.Web.UI;
public partial class Default3 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
Marks m = new Marks(1, "sad", 221);
((RadGrid)RadComboBox1.Items[0].FindControl("RadGrid1")).DataSource = m.GetMarks();
((RadGrid)RadComboBox1.Items[0].FindControl("RadGrid1")).DataBind();
}
}
protected void RadGrid1_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
Marks m = new Marks(1, "sad", 221);
((RadGrid)RadComboBox1.Items[0].FindControl("RadGrid1")).DataSource = m.GetMarks();
}
}
Marks Class
using System.Collections.Generic;
using System.Web.Caching;
/// <summary>
/// Summary description for Marks
/// </summary>
public class Marks
{
private int rollNumber;
public int RollNumber
{
get { return rollNumber; }
set { rollNumber = value; }
}
private string Subject;
public string Subject1
{
get { return Subject; }
set { Subject = value; }
}
private int score;
public int Score
{
get { return score; }
set { score = value; }
}
private string name;
public string Name
{
get { return name; }
set { name = value; }
}
public Marks(int rNo, string Sub, int sc)
{
rollNumber = rNo;
Subject = Sub;
score = sc;
}
public Marks(int rNo, string Sub, int sc, string name)
{
rollNumber = rNo;
Subject = Sub;
score = sc;
Name = name;
}
public List<Marks> GetMarks()
{
List<Marks> lstMarks = new List<Marks>();
if (System.Web.HttpContext.Current.Cache["Values"] == null)
{
for (int i = 1; i <= 200; i++)
{
for (int j = 1; j < 4; j++)
{
lstMarks.Add(new Marks(i, "Subject " + i.ToString(), i * j, "Name" + (i * j / i).ToString() + i.ToString() + j.ToString()));
}
}
System.Web.HttpContext.Current.Cache["Values"] = lstMarks;
}
else
{
lstMarks = ( List<Marks>)System.Web.HttpContext.Current.Cache["Values"];
}
return lstMarks;
}
}
I am trying to have Grid in Rad Combo Box. I am able to show grid in Combo Box but what i want to do is user should be able to filter items using grid filters. Only when he clicks on some row in grid then the information in that grid should be displayed in Combo box, the id which is hidden for any column should be accessible from Code behind.
Following is sample code that i am using.
Aspx Page
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div>
<telerik:radcombobox id="RadComboBox1" runat="server" skin="Office2007" width="100%"
nowrap="True">
<ItemTemplate>
<div>
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="False" GridLines="None"
AllowFilteringByColumn="True" AllowPaging="True" AllowSorting="True" OnNeedDataSource="RadGrid1_NeedDataSource"
EnableLinqExpressions="false" PageSize="100">
<MasterTableView AllowFilteringByColumn="true">
<RowIndicatorColumn>
<HeaderStyle Width="20px"></HeaderStyle>
</RowIndicatorColumn>
<ExpandCollapseColumn>
<HeaderStyle Width="20px"></HeaderStyle>
</ExpandCollapseColumn>
<Columns>
<telerik:GridBoundColumn DataField="Name" HeaderText="Name" SortExpression="Name"
UniqueName="Name" CurrentFilterFunction="Contains" AutoPostBackOnFilter="false"
Display="false">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Subject1" HeaderText="Subject" SortExpression="Subject1"
UniqueName="Subject1" CurrentFilterFunction="StartsWith" AutoPostBackOnFilter="false"
Display="false">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="RollNumber" HeaderText="Roll Number" SortExpression="RollNumber"
UniqueName="RollNumber" CurrentFilterFunction="GreaterThan" AutoPostBackOnFilter="false">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Score" HeaderText="Score" SortExpression="Score"
UniqueName="Score" CurrentFilterFunction="EqualTo" AutoPostBackOnFilter="false">
</telerik:GridBoundColumn>
</Columns>
</MasterTableView>
<ClientSettings AllowColumnsReorder="True" ReorderColumnsOnClient="True" AllowColumnHide="True">
<Scrolling AllowScroll="True" UseStaticHeaders="True" />
<Resizing AllowColumnResize="True" EnableRealTimeResize="True" ResizeGridOnColumnResize="True" />
</ClientSettings>
</telerik:RadGrid>
</div>
</ItemTemplate>
<Items>
<telerik:RadComboBoxItem />
</Items>
<CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation>
</telerik:radcombobox>
</div>
</form>
</body>
</html>
Code Behind
using System;
using System.Web.UI;
using Telerik.Web.UI;
public partial class Default3 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
Marks m = new Marks(1, "sad", 221);
((RadGrid)RadComboBox1.Items[0].FindControl("RadGrid1")).DataSource = m.GetMarks();
((RadGrid)RadComboBox1.Items[0].FindControl("RadGrid1")).DataBind();
}
}
protected void RadGrid1_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
Marks m = new Marks(1, "sad", 221);
((RadGrid)RadComboBox1.Items[0].FindControl("RadGrid1")).DataSource = m.GetMarks();
}
}
Marks Class
using System.Collections.Generic;
using System.Web.Caching;
/// <summary>
/// Summary description for Marks
/// </summary>
public class Marks
{
private int rollNumber;
public int RollNumber
{
get { return rollNumber; }
set { rollNumber = value; }
}
private string Subject;
public string Subject1
{
get { return Subject; }
set { Subject = value; }
}
private int score;
public int Score
{
get { return score; }
set { score = value; }
}
private string name;
public string Name
{
get { return name; }
set { name = value; }
}
public Marks(int rNo, string Sub, int sc)
{
rollNumber = rNo;
Subject = Sub;
score = sc;
}
public Marks(int rNo, string Sub, int sc, string name)
{
rollNumber = rNo;
Subject = Sub;
score = sc;
Name = name;
}
public List<Marks> GetMarks()
{
List<Marks> lstMarks = new List<Marks>();
if (System.Web.HttpContext.Current.Cache["Values"] == null)
{
for (int i = 1; i <= 200; i++)
{
for (int j = 1; j < 4; j++)
{
lstMarks.Add(new Marks(i, "Subject " + i.ToString(), i * j, "Name" + (i * j / i).ToString() + i.ToString() + j.ToString()));
}
}
System.Web.HttpContext.Current.Cache["Values"] = lstMarks;
}
else
{
lstMarks = ( List<Marks>)System.Web.HttpContext.Current.Cache["Values"];
}
return lstMarks;
}
}