C# ASP.NET-i';我正在寻找将子字符串字体更改为gridview单元格的方法
首先在绑定字段上设置C# ASP.NET-i';我正在寻找将子字符串字体更改为gridview单元格的方法,c#,asp.net,gridview,C#,Asp.net,Gridview,首先在绑定字段上设置htmlencode=“false”,如下所示 protected void Button2_Click(object sender, EventArgs e) { string srchDescription = searchDescription.Text; string slctItem = DropDownList1.SelectedItem.ToString(); con.Open(); S
htmlencode=“false”
,如下所示
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 FROM car_table WHERE Вносител = '" + slctItem + "'", con);
string descriptionText = cmdForDescription.ExecuteScalar().ToString();
bool containsDescription = descriptionText.Contains(srchDescription);
if (containsDescription)
{
SqlCommand cmd = new SqlCommand("SELECT * FROM car_table WHERE Вносител = '" + slctItem + "'", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
GridView2.DataSource = ds;
GridView2.DataBind();
con.Close();
Label2.Visible = true;
}
}
gridview的编写以下内容
<asp:BoundField DataField="Description" HeaderText="Description"
htmlencode="false" SortExpression="Description" />
if(e.Row.RowType==DataControlRowType.DataRow)
{
string textToReplace=searchDescription.Text;
字符串newText=”“+searchDescription.Text+”;
e、 Row.Cells[4]。Text=e.Row.Cells[4]。Text.Replace(textToReplace,newText);
}
哪一个是描述字段?对不起,它在我的语言中。。。最后一个是描述->非常感谢!:)很高兴帮助你:)
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 FROM car_table WHERE Вносител = '" + slctItem + "'", con);
string descriptionText = cmdForDescription.ExecuteScalar().ToString();
bool containsDescription = descriptionText.Contains(srchDescription);
if (containsDescription)
{
SqlCommand cmd = new SqlCommand("SELECT * FROM car_table WHERE Вносител = '" + slctItem + "'", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
GridView2.DataSource = ds;
GridView2.DataBind();
con.Close();
Label2.Visible = true;
}
}
<asp:BoundField DataField="Description" HeaderText="Description"
htmlencode="false" SortExpression="Description" />
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);
}