c# - ASP.NET - i'm looking for a way to change a subString font into a gridview cell -


 <asp:textbox id="searchdescription" runat="server" height="26px" width="270px"></asp:textbox>         <br />         <br />          <asp:button id="button2" runat="server" text="Търси" onclick="button2_click" />         <br />         <br /> 

so here gridview :

<asp:gridview id="gridview2" runat="server" horizontalalign="center" allowpaging="true"              autogeneratecolumns="false" cellpadding="4"             forecolor="#333333" gridlines="none">             <alternatingrowstyle backcolor="white" />             <columns>                 <asp:boundfield datafield="Марка" headertext="Марка" sortexpression="Марка" />                 <asp:boundfield datafield="Година" headertext="Година"                      sortexpression="Година" />                 <asp:boundfield datafield="Мощност" headertext="Мощност"                      sortexpression="Мощност" />                 <asp:boundfield datafield="Вносител" headertext="Вносител"                      sortexpression="Вносител" />                 <asp:boundfield datafield="description" headertext="description"                      sortexpression="description" />             </columns>             <editrowstyle backcolor="#2461bf" />             <footerstyle backcolor="#507cd1" font-bold="true" forecolor="white" />             <headerstyle backcolor="#507cd1" font-bold="true" forecolor="white" />             <pagerstyle backcolor="#2461bf" forecolor="white" horizontalalign="center" />             <rowstyle backcolor="#eff3fb" />             <selectedrowstyle backcolor="#d1ddf1" font-bold="true" forecolor="#333333" />             <sortedascendingcellstyle backcolor="#f5f7fb" />             <sortedascendingheaderstyle backcolor="#6d95e1" />             <sorteddescendingcellstyle backcolor="#e9ebef" />             <sorteddescendingheaderstyle backcolor="#4870be" />         </asp:gridview> 

i have description text field , dropdownlist , button generates query takes out db * table 1 of column equal selected item dropdown , if in description cell contains substring description text field. want when description cell appears gridview, substring text field bolded.

here button method:

protected void button2_click(object sender, eventargs e)     {         string srchdescription = searchdescription.text;         string slctitem = dropdownlist1.selecteditem.tostring();          con.open();          sqlcommand cmdfordescription = new sqlcommand("select description car_table Вносител = '" + slctitem + "'", con);         string descriptiontext = cmdfordescription.executescalar().tostring();         bool containsdescription = descriptiontext.contains(srchdescription);          if (containsdescription)         {              sqlcommand cmd = new sqlcommand("select * car_table Вносител = '" + slctitem + "'", con);             sqldataadapter da = new sqldataadapter(cmd);             dataset ds = new dataset();             da.fill(ds);             gridview2.datasource = ds;             gridview2.databind();             con.close();             label2.visible = true;          }     }  

first set htmlencode="false" on bound field this.

<asp:boundfield datafield="description" headertext="description"                   htmlencode="false"   sortexpression="description" /> 

the in rowdatabound of gridview write following.

if(e.row.rowtype == datacontrolrowtype.datarow) {    string texttoreplace = searchdescription.text;    string newtext = "<b>" +searchdescription.text + "</b>";    e.row.cells[4].text =e.row.cells[4].text.replace(texttoreplace, newtext);     } 

Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -