在c#中加粗字符串

时间:2014-12-22 11:18:07

标签: c# asp.net .net

我有一个字符串,我需要添加方括号并将字体更改为粗体。我也尝试了这个,并没有像预期的那样w。不前。

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值。对于Ex:GroupID列值应该类似于

  [Nestle] - N/A where `[Nestle] -` only should be bold.

1 个答案:

答案 0 :(得分:0)

你不能使字符串变粗。您可以做的是用于显示字符串粗体的控件。

如果这是gridview,您可以使用grd_RowDataBound命令使特定单元格变为粗体,例如 如果您要在单元格[0]中存在要加粗的值:

e.Row.Cells [0] .Font.Bold = true