Reputation: 839
<asp:Label ID="lblMRNNumber" runat="server" Text='<%# String.Concat(Eval("MRNNumber"))%>'> </asp:Label>
It display as
MRN-01
MRN-02
MRN-03
my requirement is
'MRN-01'
'MRN-02'
'MRN-03'
Text='<%# String.Concat("'",Eval("MRNNumber"),"'")%>' This gives error!
how to do this!
Upvotes: 2
Views: 1715
Reputation: 28403
According to Gridview Item formatting:
Method 1:
Use BoundField, and intercept the GridView's RowDataBound event, in the RowDataBound event, we can get the Binded Data from the certain GridView Row's Cell
For 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 + "'";
}
}
or:
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 + "'";
}
}
Method 2:
<asp:TemplateField HeaderText="TemplatePrice">
<ItemTemplate>
<asp:Label ID="lblMRNNumber" runat="server" Text='<%# AddDollar(Eval("MRNNumber").ToString()) %>'> </asp:Label>
</ItemTemplate>
</asp:TemplateField>
AddDolloar is the helper function defined in page class:
protected string AddDollar(string mystr)
{
return "'" + mystr + "'";
}
Upvotes: 1
Reputation: 4596
Try this
Text="<%#(Eval("MRNNumber","'{0}'"))%>"
This will be treated as
text=Eval("MRNNumber","'{0}'")
Upvotes: 1