Singaravelan
Singaravelan

Reputation: 839

Concatenation with single quote in String.Concat

<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

Answers (2)

Vignesh Kumar A
Vignesh Kumar A

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 + "'";
}

Take a look at this link

Upvotes: 1

Md. Parvez Alam
Md. Parvez Alam

Reputation: 4596

Try this

Text="<%#(Eval(&quot;MRNNumber&quot;,&quot;'{0}'&quot;))%>"

This will be treated as

text=Eval("MRNNumber","'{0}'")

Upvotes: 1

Related Questions