2014-12-22 79 views
-3

我有一个字符串,我需要添加方括号并将字体更改为粗体。此外,我尝试了这一点,它不像预期的那样出色。现在在c中粗体字符串#

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我会通过A N/A值。例如:GroupID列的值应与

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

你在哪里打算使用此代码? –

+0

我正在使用此代码在gridview中插入字段值。 – Michael

+0

显示该代码。 –

回答

0

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

如果这是gridview,则可以使用grd_RowDataBound命令使特定单元格变为粗体,例如, 如果你想大胆值在单元格[0]存在:

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