繁体   English   中英

Gridview中的string.replace数据绑定列

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM