【发布时间】:2014-12-22 11:18:06
【问题描述】:
我有一个字符串,我需要添加方括号并将字体更改为粗体。我也试过这个,它没有按预期工作。
string strID = "<b>" + strGroupID + "-</b>";
现在这个字符串产生类似Nestle-的结果,结果应该是这样的[Nestle]-
非常感谢您对此的任何帮助。
代码
protected void gvComm_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName.Equals("AddNew"))
{
string strGroupID = ((DropDownList)gvComm.FooterRow.FindControl("ddlKey")).SelectedValue;
string strComm = ((TextBox)gvComm.FooterRow.FindControl("lblOwner")).Text.Trim();
string strLeader = ((TextBox)gvComm.FooterRow.FindControl("lblIT")).Text.Trim();
string strName = ((TextBox)gvComm.FooterRow.FindControl("lblFTC")).Text.Trim();
string strID = "<b>" + strGroupID + "-</b>";
bool success = false;
success = InsertComm(strGroupID , strComm, strLeader, strName , strID);
if (success)
{
ClientScript.RegisterStartupScript(Page.GetType(), "alert", "alert('Data Inserted Successfully');window.location='Mapping.aspx';", true);
}
else
{
ClientScript.RegisterStartupScript(Page.GetType(), "alert", "alert('Insert Operation Failed');window.location='Mapping.aspx';", true);
}
}
}
public static bool InsertComm(string strGroupID , string strComm, string strLeader, string strName , string strID)
{
bool success = false;
string strcon = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
using (SqlConnection connection = new SqlConnection(strcon))
{
connection.Open();
using (SqlCommand oCommand = connection.CreateCommand())
{
oCommand.CommandText = "insert into Comm values ('" + strGroupID + " " + 'N/A' + "','" + strComm+ "','" + strLeader+ "','" + strName + "','" + strID+ "')";
oCommand.ExecuteNonQuery();
success = true;
}
}
return success;
}
如果您看到 strGroupID,我将传递一个 N/A 值。例如:GroupID 列值应该是这样的
[Nestle] - N/A where `[Nestle] -` only should be bold.
【问题讨论】:
-
您打算在哪里使用此代码?
-
我正在使用此代码在 gridview 中插入字段值。
-
您不能将字符串设为粗体。某些显示为粗体的文本仅在特定 UI 的上下文中才有意义。例如。在网页上,您将使用 HTML CSS,但 WPF 视图上的标签将完全不同。您需要提供 UI 的详细信息。
-
可能是gridview上应用的css不允许加粗。这个问题可能有很多原因。
-
是的,那你是怎么展示的呢?加载到任何控件,如
Label?还是来自数据库?你能在显示Nestle-的地方显示html/aspx吗?