[英]string.replace databound column in Gridview
我目前正在將字符串注釋從數據庫中提取到gridview中以顯示給用戶。 在整個字符串中,我已將<br/>
放置在需要換行的位置,但是我想知道如何用“ Environment.Newline”替換<br/>
。 該列只是一個邊界域。
<Columns>
<asp:BoundField HeaderText="Comment" DataField="UAComment" />
</Columns>
並使用適配器和Fill()填充表格:
adapter = new SqlDataAdapter(queryString, connection);
connection.Open();
adapter.SelectCommand = command;
recordsFound = adapter.Fill(table);
results.Text = recordsFound + " records matching query";
connection.Close();
感謝您提供任何信息。
ps:也已經嘗試過用換行符構建字符串/將字符串提交到數據庫,但是似乎無法以正確的格式將其拉出數據庫。
public void Group(String message)
{
log.Append(": Group :");
log.AppendFormat(message);
log.Append("<br/>");
}
public String GetLog()
{
log.Replace("<br/>", Environment.NewLine);
return log.ToString();
}
還用@“ \\ n”,“ \\ n”,@“ \\ r”,“ \\ r”替換了“ Environment.Newline”
最簡單的解決方案是使用模板字段而不是綁定字段,並使用當前列值在模板字段中添加綁定文字。 使用它會以html格式呈現所有內容,並且換行符自動出現。
范例:
<asp:TemplateField>
<HeaderTemplate>
Comment
</HeaderTemplate>
<ItemTemplate>
<asp:Literal runat="server" ID="Literal1" Text='<%# Eval("UAComment") %>' />
</ItemTemplate>
</asp:TemplateField>
希望這能解決您的問題
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.