获取错误对象引用未设置为对象实例

编程入门 行业动态 更新时间:2024-10-26 17:23:09
本文介绍了获取错误对象引用未设置为对象实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我不知道为什么在gridview中删除时出现以下erorr错误.请找出问题所在.

i don''t know why i am getting error the following erorr while deleting in gridview. pls figure out whats the problem.

object refereance not set to instance of an object

这是代码

here is the code

protected void _rowdeleting(object sender, GridViewDeleteEventArgs e) { //String Username = GridView1.DataKeys[e.RowIndex].Value.ToString(); GridViewRow row = (GridViewRow)GridView1.Rows[e.RowIndex]; Label user = (Label)row.FindControl("UserName"); string Username = user.Text; //string Username = System.Convert.ToString(User); // string Username = System.Convert.ToString(Username); // instantiate BAL Businesslayer pBAL = new Businesslayer(); try { pBAL.Delete(Username); lblMessage.Text = "Record Deleted Successfully."; } catch (Exception ee) { lblMessage.Text = ee.Message.ToString(); } finally { pBAL = null; } // GridView1.EditIndex = -1; // Refresh the list BindGrid(); }

推荐答案

这取决于您在哪里得到错误: It depends where you are getting the error: string Username = user.Text;

表示找不到您的控件用户名. 否则,假设您的业务层是从List< T>派生的. (或类似),或支持IEnumerable-检查您的构造函数.如果应该填充列表,则似乎没有添加用户名条目. 假定您有一个try-catch块,我认为该错误出在您的标签中,这暗示该标签.

Would mean that your control UserName has not been found. Otherwise, assuming that your Businesslayer is derived from List<T> (or similar), or supports IEnumerable - check your constructor. If it is supposed to populate the list then it doesn''t appear to be adding the Username entry. Given you have a try-catch block, I assume the error is in your label, which would imply the latter.

如何填充gridview. 在该方法中,是否有任何会话或查询字符串值正在使用,请再次检查此内容. 然后检查一下,名称findcontrol("username")与网格视图项目模板标签id相同.是否存在任何拼写错误. 如果相同,则检查第一点. 希望它有用. 如果没有回复我, 来自 vikranth reddy. How you are filling the gridview. in that method is there any session or query string values are using once check this thing also. and check this thing one, the name findcontrol("username") is same as grid view item template label id.is there any spelling mistakes. if it is same then check first point. hope it is useful. if not reply me, from vikranth reddy.

更多推荐

获取错误对象引用未设置为对象实例

本文发布于:2023-11-16 02:35:35,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1600232.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:对象   设置为   实例   错误

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!