日期:2014-05-19  浏览次数:20366 次

ASP.net GridView急急急...............
txtuser.Text   =   ((TextBox)grid.Rows[1].Cells[1].FindControl( "员工名称 ")).Text.Trim();

这句老是提示 "未将对象引用设置到对象的实例 "

------解决方案--------------------
<ItemTemplate> 位置一
</ItemTemplate>
<AlternatingItemTemplate > 位置二
</AlternatingItemTemplate>
如果用到这两个模板,位置一,位置二,两个位置都要放在控件才可以用FindControl( "控件Id ")来取得,如果只有一处地方有,就会出现像你所说的错误.
------解决方案--------------------
txtuser.Text = ((TextBox)grid.Rows[1].Cells[1].FindControl( "员工名称 ")).Text.Trim();
员工名称==> 控件ID(tbUserName)
txtuser.Text = ((TextBox)grid.Rows[1].Cells[1].FindControl( "tbUserName ")).Text.Trim();
------解决方案--------------------
string str=((TextBox)e.Item.Cells[1].Controls[0]).Text;

试试这个
------解决方案--------------------
推荐个GRIDVIEW的实例,包含颇多
[url]http://blog.csdn.net/21aspnet/archive/2007/03/25/1540301.aspx[url]