<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!
怎么做!
答案 0 :(得分:1)
方法1:
使用BoundField,并拦截GridView的RowDataBound事件 RowDataBound事件,我们可以从某个GridView获取Binded Data Row的细胞
对于 Ex :
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 + "'";
}
答案 1 :(得分:1)
试试这个
Text="<%#(Eval("MRNNumber","'{0}'"))%>"
这将被视为
text=Eval("MRNNumber","'{0}'")