how to change a particular font color in gridview with asp.net
how to change a particular font color in gridview with asp.net
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
urmila kandariPosted Mar 31, 2009, 3:17 AM
<
head runat="server"> <title>Untitled Pagetitle> <style type="text/css"> .highlight{
text-decoration:none; font-weight:bold; color:black; background:yellow;}
style> head><
body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server" /> <div>Enter first name to search:div> <div><asp:TextBox ID="txtSearch" runat="server" AutoPostBack="True" OnTextChanged="txtSearch_TextChanged">asp:TextBox> div> <div> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:GridView ID="grdSearch" runat="server" AutoGenerateColumns="false"> <Columns> <asp:TemplateField HeaderText="FirstName"> <ItemTemplate> <asp:Label ID="lblFirstName" runat="server"><%# Highlight(Eval("FirstName").ToString())%>asp:Label>ItemTemplate> asp:TemplateField> <asp:TemplateField HeaderText="LastName"><ItemTemplate><asp:Label ID="lblLastName" runat="server"><%#Eval("LastName")%>asp:Label>ItemTemplate> asp:TemplateField> <asp:TemplateField HeaderText="Location"><ItemTemplate><asp:Label ID="lblLocation" runat="server"><%#Eval("Location")%>asp:Label>ItemTemplate> asp:TemplateField> Columns> asp:GridView> ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="txtSearch" EventName="TextChanged" /> Triggers> asp:UpdatePanel> <asp:Button ID="btn" Text="save" runat="server" OnClick="btn_Click" /> <asp:Label ID="lb" runat="server">asp:Label> div> form> body>cs
public void searchtext(){
datafill();
dv =
new DataView();dv =
new DataView(dt); string SearchExpression = null; if(txtSearch.Text==""){
lb.Text =
"please enter keyword";}
else{
lb.Visible =
false; if (!String.IsNullOrEmpty(txtSearch.Text)){
SearchExpression =
string.Format("{0} '%{1}%'", grdSearch.SortExpression, txtSearch.Text);}
dv.RowFilter =
"FirstName like" + SearchExpression; int i = dv.Count;grdSearch.DataSource = dv;
grdSearch.DataBind();
}
}
public string Highlight(string InputTxt){
string Search_Str = txtSearch.Text.ToString(); // Setup the regular expression and add the Or operator. Regex RegExp = new Regex(Search_Str.Replace(" ","").Trim(), RegexOptions.IgnoreCase); // Highlight keywords by calling the //delegate each time a keyword is found. return RegExp.Replace(InputTxt, new MatchEvaluator(ReplaceKeyWords));// Set the RegExp to null.RegExp =
null;}
public string ReplaceKeyWords(Match m){
return "" + m.Value + "";}
protected void btn_Click(object sender, EventArgs e){
searchtext();
}
urmila kandariPosted Mar 31, 2009, 3:17 AM
<
head runat="server"> <title>Untitled Pagetitle> <style type="text/css"> .highlight{
text-decoration:none; font-weight:bold; color:black; background:yellow;}
style> head><
body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server" /> <div>Enter first name to search:div> <div><asp:TextBox ID="txtSearch" runat="server" AutoPostBack="True" OnTextChanged="txtSearch_TextChanged">asp:TextBox> div> <div> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:GridView ID="grdSearch" runat="server" AutoGenerateColumns="false"> <Columns> <asp:TemplateField HeaderText="FirstName"> <ItemTemplate> <asp:Label ID="lblFirstName" runat="server"><%# Highlight(Eval("FirstName").ToString())%>asp:Label>ItemTemplate> asp:TemplateField> <asp:TemplateField HeaderText="LastName"><ItemTemplate><asp:Label ID="lblLastName" runat="server"><%#Eval("LastName")%>asp:Label>ItemTemplate> asp:TemplateField> <asp:TemplateField HeaderText="Location"><ItemTemplate><asp:Label ID="lblLocation" runat="server"><%#Eval("Location")%>asp:Label>ItemTemplate> asp:TemplateField> Columns> asp:GridView> ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="txtSearch" EventName="TextChanged" /> Triggers> asp:UpdatePanel> <asp:Button ID="btn" Text="save" runat="server" OnClick="btn_Click" /> <asp:Label ID="lb" runat="server">asp:Label> div> form> body>cs
public void searchtext(){
datafill();
dv =
new DataView();dv =
new DataView(dt); string SearchExpression = null; if(txtSearch.Text==""){
lb.Text =
"please enter keyword";}
else{
lb.Visible =
false; if (!String.IsNullOrEmpty(txtSearch.Text)){
SearchExpression =
string.Format("{0} '%{1}%'", grdSearch.SortExpression, txtSearch.Text);}
dv.RowFilter =
"FirstName like" + SearchExpression; int i = dv.Count;grdSearch.DataSource = dv;
grdSearch.DataBind();
}
}
public string Highlight(string InputTxt){
string Search_Str = txtSearch.Text.ToString(); // Setup the regular expression and add the Or operator. Regex RegExp = new Regex(Search_Str.Replace(" ","").Trim(), RegexOptions.IgnoreCase); // Highlight keywords by calling the //delegate each time a keyword is found. return RegExp.Replace(InputTxt, new MatchEvaluator(ReplaceKeyWords));// Set the RegExp to null.RegExp =
null;}
public string ReplaceKeyWords(Match m){
return "" + m.Value + "";}
protected void btn_Click(object sender, EventArgs e){
searchtext();
}
Vijaya KadiyalaPosted Mar 10, 2009, 10:18 AM
Hi
Check out the below link
http://msdn.microsoft.com/en-us/library/aa479342.aspx
Thanks -- Vijaya Kadiyala
http://dotnetvj.blogspot.com
Pramod Kumar NandagiriPosted Mar 8, 2009, 10:17 AM
U TRY WITH THIS CODE I GOT WITH THIS //
/* IN CODE BIHIND */
using
System.Text.RegularExpressions;public
string getcompany(string s){
string strcolor=""; string strsearch="na"; string strformat=strcolor+strsearch+""; string strresult=Regex.Replace(s,strsearch,strformat,RegexOptions.IgnoreCase); return(strresult);}
/*SEE THE ITEMTEMPLATE FIELD IN THE SOURCE CODE */
<
html xmlns="http://www.w3.org/1999/xhtml"><
head runat="server"> <title>Untitled Pagetitle> head><
body> <form id="form1" runat="server"> <div> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="CustomerID" DataSourceID="SqlDataSource1"> <Columns> <asp:BoundField DataField="CustomerID" HeaderText="CustomerID" ReadOnly="True" SortExpression="CustomerID" /> <asp:TemplateField HeaderText="CompanyName"> <ItemTemplate> <asp:Label ID="lb3" runat="server" Text='<%#getcompany((string)DataBinder.Eval(Container,"DataItem.CompanyName")) %>'> asp:Label> ItemTemplate> asp:TemplateField> Columns> asp:GridView> div> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString2 %>" SelectCommand="SELECT [CustomerID], [CompanyName] FROM [Customers]"> asp:SqlDataSource> <br /> <br /> <br /> <asp:TextBox ID="TextBox1" runat="server">asp:TextBox> form> body> html>