GRIDVIEW绑定到了数据源
在其中有个是模版列:
.......前面省略....
<asp:HyperLinkfile></asp:HyperLink>
<asp:TextBox id="txtbox" runat="server" text='<%# Eval("数据字段")%>'></asp:TextBox>
....后面省略......
以上代码大致就是这样 ,其他都是commandfile和buttfile
现在我需要在数据绑定的时候更改txtbox的text属性值,截取它一定的长度,
然后我在后台databind事件中需要根据txtbox的text的长度来截取,朝过5个字符就用省略号代替,
然后我用到了e.row.cell[数字]这个办法来更改,结果我发现HyperLinkfile绑定的值和textbox的值都无发更该 而普通列buttfile列这样就可以更改其绑定的值,当e.row.cell[数字]到HyperLinkfile和textbox单元格的时候 就是显示不出来我要更该的内容以上大致意思就是这样 请问大家分析下是什么原因 并给出解决的方法

解决方案 »

  1.   

    textbox 和 hypelink不是用e.row.cell[],而是用findcontrol來解決。        TextBox txtReason = (TextBox)row.Cells[17].FindControl("txtReason");
            TextBox txtRe = (TextBox)row.Cells[18].FindControl("txtRe");
            //string reason = txtReason.Text.Trim();
            //string re = txtReason.Text.Trim();
            //if()
      

  2.   

    前台:
          <%# SubStr(Eval("数据字段"),10)%>
    后台:
        public string SubStr(object caption, int nLeng)    {        string sString = caption.ToString().Trim();         if (sString.Length <= nLeng)        {            return sString;        }        else        {            string sNewStr = sString.Substring(0, nLeng);            sNewStr = sNewStr + "...";            return sNewStr;        }    }
      

  3.   

    错了,应该是截取5个
     <%# SubStr(Eval("数据字段"),5)%>
      

  4.   


    用一楼的方法
    然后获取值txtReason.text