Click here to Skip to main content
15,895,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I have a string in my gridview.The string consist of "Fatty acyl CoA from the cytosol reacts with carnitine in the outer mitochondrial membrane, forming fatty acyl carnitine." quoted text.


The solution what i need is I need to replace the "acyl carnitine" word in string with "acyl-carnitine".I have that string in grid view and i dont know how to get the string from gridview and replace it with that word.
Posted

HI
You can check in gridview row databound event.In that find the value of that column and replace the string with new value

Tyr this ...
 
Share this answer
 
ashishbi is right...

Try this code..


C#
<asp:GridView ID="GridView1" AutoGenerateColumns="false" runat="server"
            onrowdatabound="GridView1_RowDataBound">
            <Columns>

                <asp:TemplateField HeaderText="Column 1">
                    <ItemTemplate>
                        <asp:TextBox ID="txtbox" Text='<%# Eval("Name") %>' runat="server"></asp:TextBox>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>




C#
Public partial class test : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e) {

            if (Page.IsPostBack)
            { }
            else
            {
                DataTable dt = new DataTable();
                dt.Columns.Add("Name", typeof(string));
                dt.Rows.Add("Fatty acyl CoA from the cytosol reacts with carnitine in the outer mitochondrial membrane, forming fatty acyl carnitine");
                dt.Rows.Add("Fatt acyl carnitine");
                
                GridView1.DataSource = dt;
                GridView1.DataBind();
            }
        
        }

        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {  

               var txt  =  e.Row.FindControl("txtbox") as TextBox;
               txt.Text = txt.Text.Replace("acyl carnitine", "acyl-carnitine");

            }

        }

         

    }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900