如何使用c#从gridview中的字符串替换单个单词 [英] How to replace a single word from string in gridview using c#

查看:99
本文介绍了如何使用c#从gridview中的字符串替换单个单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我的gridview中有一个字符串。字符串由来自胞质溶胶的脂肪酰基CoA与线粒体外膜中的肉毒碱反应,形成脂肪酰基肉碱。引用文本。





我需要的解决方案是我需要更换酰基肉碱字样在字符串中带有 acyl-carnitine 。我在网格视图中有该字符串,我不知道如何从gridview获取字符串并将其替换为该字。

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.

推荐答案

HI

你可以检查gridview行数据绑定事件。在那里找到该列的值并用新值替换字符串



Tyr这...
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 ...


ashishbi是对的...



试试这个代码..





ashishbi is right...

Try this code..


<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>













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");

            }

        }

         

    }


这篇关于如何使用c#从gridview中的字符串替换单个单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆