日期:2014-05-17  浏览次数:20430 次

e.Row.Cells[0].Text GridView问题
e.Row.Cells[0].Text这样能获取到数据,
但诡异的是只能获取到数字,

英文和中文就获取不到?请问高手,是怎么回事

------解决方案--------------------
后面加.ToString()试试
------解决方案--------------------
你获取的这个Text在页面现实了吗?
------解决方案--------------------
探讨
Cells[0].Text

------解决方案--------------------
奉劝你正规做法,使用FindControl来找到Cells中(不确定)的某一个单元格里边真正的对象,而不是搞什么[0].Text。
------解决方案--------------------
e.Row.Attributes.Add("onclick", "document.getElementById('txtYWCode').value=" + e.Row.Cells[5].Text + "");

你要设置的值不单单是数字吧?你上面这样设置如果e.Row.Cells[5].Text不是数字,直接出错,修改为:

e.Row.Attributes.Add("onclick", "document.getElementById('txtYWCode').value='" + e.Row.Cells[5].Text + "'");

------解决方案--------------------
用一个控件呈现你的文本

用findcontrol去找控件 然后读取它的属性。
------解决方案--------------------
你看一下源代码,会发现onclick是这样的:
onclick="javascript:document.getElementById('txtYWCode').value=哈哈XXX"

值没加“,”,js会当作是变量来解析。这样就产生语法错误了,js直接罢工!
------解决方案--------------------
探讨
e.Row.Attributes.Add("onclick", "document.getElementById('txtYWCode').value=" + e.Row.Cells[5].Text + "");

你要设置的值不单单是数字吧?你上面这样设置如果e.Row.Cells[5].Text不是数字,直接出错,修改为:

e.Row.Attributes.Add("onclick"……

------解决方案--------------------
楼主,你是不是想说这个?
要先设置主键,主键是返回表的字段名
GridView1.DataKeys[e.RowIndex]["字段名"].ToString();
------解决方案--------------------
如果不是使用模版列的话,这样是可以获取到绑定的文本e.Row.Cells[0].Text
C# code
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes.Add("onclick", "document.getElementById('TextBox1').value='" + e.Row.Cells[0].Text + "'");
        }
    }