locked
Remove Character RRS feed

  • Question

  • User-1499457942 posted

    Hi

      I have below string in Database field.

    'Apple',Mango',Banana' . I want when retreived in Gridview column it should be displayed like Apple,Mango,Banana

    Thanks

    Wednesday, September 19, 2018 9:59 AM

Answers

  • User-1171043462 posted

    This way

    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
            <Columns>
                <asp:TemplateField HeaderText="Fruits">
                    <ItemTemplate>
                        <%# Eval("Fruits").ToString().Replace("'", "") %>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
    </asp:GridView>
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            DataTable dt = new DataTable();
            dt.Columns.AddRange(new DataColumn[1] { new DataColumn("Fruits") });
            dt.Rows.Add("'Apple',Mango',Banana'");
            GridView1.DataSource = dt;
            GridView1.DataBind();
        }
    }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, September 19, 2018 2:25 PM

All replies

  • User-821857111 posted
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Cells[1].Text = e.Row.Cells[1].Text.Replace("'","");
            }
        }

    Change the index as needed to reference the column you actually want to affect. The index is 0 based, so if your text appears in the first column, change it to e.Rows.Cells[0].Text = e.Rows.Cells[0].Text.Replace(...).

    Wednesday, September 19, 2018 12:40 PM
  • User-1171043462 posted

    This way

    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
            <Columns>
                <asp:TemplateField HeaderText="Fruits">
                    <ItemTemplate>
                        <%# Eval("Fruits").ToString().Replace("'", "") %>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
    </asp:GridView>
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            DataTable dt = new DataTable();
            dt.Columns.AddRange(new DataColumn[1] { new DataColumn("Fruits") });
            dt.Rows.Add("'Apple',Mango',Banana'");
            GridView1.DataSource = dt;
            GridView1.DataBind();
        }
    }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, September 19, 2018 2:25 PM
  • User-1716253493 posted

    SELECT REPLACE(fieldname, '''','') as fieldname

    Thursday, September 20, 2018 2:01 AM
  • User-1490431322 posted

    Yes, I completely agree with you, sir...

    SELECT REPLACE(fieldname, '''','') as fieldname

    Monday, September 24, 2018 7:10 AM