<asp:Label ID="lblMRNNumber" runat="server" Text='<%# String.Concat(Eval("MRNNumber"))%>'> </asp:Label>
它显示为
MRN-01
MRN-02
MRN-03
我的要求是
"MRN-01"
"MRN-02"
"MRN-03"
Text='<%# String.Concat("'",Eval("MRNNumber"),"'")%>' This gives error!
怎么做!
试试这个
Text="<%#(Eval("MRNNumber","'{0}'"))%>"
这将被视为
text=Eval("MRNNumber","'{0}'")
根据网格视图项目格式:
方法一:
使用 BoundField,并在RowDataBound 事件,我们可以从某个 GridView 获取绑定数据行的单元格
例如:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[2].Text = "'" + e.Row.Cells[2].Text + "'";
}
}
或:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label lbl_Name = (Label)e.Row.FindControl("lblMRNNumber");
lbl_Name.Text = "'" + lbl_Name.Text + "'";
}
}
方法2:
<asp:TemplateField HeaderText="TemplatePrice">
<ItemTemplate>
<asp:Label ID="lblMRNNumber" runat="server" Text='<%# AddDollar(Eval("MRNNumber").ToString()) %>'> </asp:Label>
</ItemTemplate>
</asp:TemplateField>
AddDolloar 是在页面类中定义的帮助程序函数:
protected string AddDollar(string mystr)
{
return "'" + mystr + "'";
}
看看这个链接