首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

e.Row.Cells[0].Text GridView有关问题

2012-06-12 
e.Row.Cells[0].TextGridView问题e.Row.Cells[0].Text这样能获取到数据,但诡异的是只能获取到数字,英文和

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 + "'");        }    } 

热点排行