我使用CKEditor输入详细信息(详细信息包含html元素)。之后,细节将绑定到网格中。在这里我想在工具提示中没有html标签显示这些细节。
protected void grdStepMain_RowDataBound(object sender, GridViewRowEventArgs e)
{
int i = 0;
if (e.Row.RowType == DataControlRowType.DataRow)
{
foreach (TableCell cell in e.Row.Cells)
{
i++;
string description = cell.Text;
if (cell.Text.Length > 8 && (i == 2))
cell.Text = cell.Text.Substring(0, 8) + "....";
string newdescription = Regex.Replace(description, @"<[^>]+>| ", "").Trim();
cell.ToolTip = Regex.Replace(newdescription, @"<[^>]+>| ", "").Trim();
}
}
}
但它不起作用请帮助我。例如:
string str= " <h1><span style="font-family:courier new,courier,monospace"><strong>457457</strong> 544444444444457457457</span>";
The result in tooltip should be 457457544444444444457457457
请帮助。 问候 jithesh
答案 0 :(得分:2)
int i = 0;
string newdescription = "";
if (e.Row.RowType == DataControlRowType.DataRow)
{
foreach (TableCell cell in e.Row.Cells)
{
i++;
string description = cell.Text;
if (cell.Text.Length > 8 && (i == 2))
{
string a = Regex.Replace(description, @"<.+?>| ", "").Trim();
cell.Text = a.Substring(0, 8) + "....";
}
if (i == 2)
{
newdescription = Regex.Replace(description, @"<.+?>| ", "").Trim();
}
cell.ToolTip = Regex.Replace(newdescription, @"<.+?>| ", "").Trim();
}
}
答案 1 :(得分:0)
如果您想要显示没有 HTML标记的详细信息,只需使用如下所示的网格视图的BoundField
:
你走了,
<asp:BoundField DataField="yourcolumnid" HeaderText="Column Text" ItemStyle-Width="30" HtmlEncode="false" />
希望有所帮助