|
Requirements |
|
| RadControls version |
2008.1.415.20 |
| .NET version |
2.0 |
| Visual Studio version |
2005 |
| programming language |
C# |
| browser support |
all browsers supported by RadControls |
PROJECT DESCRIPTION
This sample project demonstrates how to search and highlight a GridGroupHeader text defined through a dropdownlist control inside the CommandItemTemplate
ASPX:
| <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> |
| <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> |
| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> |
| <html xmlns="http://www.w3.org/1999/xhtml"> |
| <head runat="server"> |
| <title>Untitled Page</title> |
| </head> |
| <body> |
| <form id="form1" runat="server"> |
| <asp:ScriptManager ID="ScriptManager1" runat="server" /> |
| <div> |
| <br /> |
| <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString2 %>" |
| SelectCommand="SELECT [ShipName], [ShipCountry], [OrderID] FROM [Orders]"></asp:SqlDataSource> |
| <br /> |
| </div> |
| <br /> |
| <telerik:RadGrid ID="RadGrid1" DataSourceID="SqlDataSource1" Skin="Hay" AllowPaging="true" PageSize="5" AutoGenerateColumns="True" runat="server"> |
| <MasterTableView CommandItemDisplay="Top" DataSourceID="SqlDataSource1"> |
| <CommandItemTemplate> |
| <table> |
| <tr> |
| <td> |
| <asp:Label ID="Label1" runat="server" BackColor="Green" Text="Choose a Ship Country"></asp:Label> |
| </td> |
| <td> |
| <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource1" |
| DataTextField="ShipCountry" DataValueField="ShipCountry" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" > |
| </asp:DropDownList> |
| </td> |
| </tr> |
| </table> |
| </CommandItemTemplate> |
| <GroupByExpressions> |
| <telerik:GridGroupByExpression> |
| <GroupByFields> |
| <telerik:GridGroupByField FieldName="ShipCountry" FieldAlias="ShipCountry" FormatString="" HeaderText=""/> |
| </GroupByFields> |
| <SelectFields> |
| <telerik:GridGroupByField FieldName="ShipCountry" FieldAlias="ShipCountry" FormatString="" HeaderText=""/> |
| </SelectFields> |
| </telerik:GridGroupByExpression> |
| </GroupByExpressions> |
| <RowIndicatorColumn Visible="False"> |
| <HeaderStyle Width="20px" /> |
| </RowIndicatorColumn> |
| <ExpandCollapseColumn Resizable="False" Visible="False"> |
| <HeaderStyle Width="20px" /> |
| </ExpandCollapseColumn> |
| <EditFormSettings> |
| <PopUpSettings ScrollBars="None" /> |
| </EditFormSettings> |
| </MasterTableView> |
| </telerik:RadGrid><br /> |
| </form> |
| </body> |
| </html> |
CS:
| using System; |
| using System.Data; |
| using System.Configuration; |
| using System.Web; |
| using System.Web.Security; |
| using System.Web.UI; |
| using System.Web.UI.WebControls; |
| using System.Web.UI.WebControls.WebParts; |
| using System.Web.UI.HtmlControls; |
| using Telerik.Web.UI; |
| public partial class _Default : System.Web.UI.Page |
| { |
| protected void Page_Load(object sender, EventArgs e) |
| { |
| } |
| protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) |
| { |
| DropDownList DropDownList1 = (DropDownList)sender; |
| int count = RadGrid1.MasterTableView.PageCount; |
| int flag = 0; |
| for (int i = 0; i < count; i++) |
| { |
| RadGrid1.CurrentPageIndex = i; |
| RadGrid1.Rebind(); |
| foreach (GridItem item in RadGrid1.MasterTableView.Controls[0].Controls) |
| { |
| if (item is GridGroupHeaderItem) |
| { |
| GridGroupHeaderItem Item = (GridGroupHeaderItem)item; |
| string strText = Item.DataCell.Text; |
| string[] arr = strText.Split(':'); |
| DataRowView groupDataRow = (DataRowView)Item.DataItem; |
| string searchText = groupDataRow[arr[0]].ToString(); |
| if (searchText == DropDownList1.Text) |
| { |
| searchText = "<span style='color: red;' >" + searchText + "</span>"; |
| Item.DataCell.Text = arr[0] + ":" + " " + searchText; |
| flag = 1; |
| break; |
| } |
| } |
| } |
| if (flag == 1) |
| break; |
| } |
| } |
| } |
Princy.