在gridview控件中删除事件行。(Row Deleting event in gridview control.)

   IT问题网   2021-02-22 00:00:00

问 题

我正在尝试从gridview控件中的用户表中选择userid时从角色表中删除userid和groupid。我得到了错误。任何人都可以在查询中弄清楚问题。



对象引用未设置为对象的实例。






 受保护  void  _rowdeleting( object  sender,gridviewdeleteeventargs e)
{
gridviewrow row =(gridviewrow)gridview1 .rows [e.rowindex];
标签lbldeletename =(标签)row.findcontrol(" lblusername");
textbox textname =(textbox)row.findcontrol(" txtusername");
maconn.open();
sqlcommand cmd = new sqlcommand(" 删除来自roles(userid,groupid)select userid from users where username ='" + textname.text + " '",maconn);
cmd.executenonquery();
maconn.close();
bind();

}

解决方案

lbldeletename , textname 或 maconn 很可能为null,因为prerak建议使用调试器以确切原因。

查看掌握visual studio 2010中的调试 - 初学者指南 [ ^ ]



我刚注意到你甚至没有使用 lbldeletename 留下 textname 或 maconn 作为您的例外的可能来源。

我建议将用户名设置为gridview的datakey



并做类似的编码。

 受保护  void  _rowdeleting( obj ect  sender,gridviewdeleteeventargs e)
{
string username = grdview1.datakeys [e.rowindex] .value.tostring() ;
maconn.open();
sqlcommand cmd = new sqlcommand(" 删除从roles(userid,groupid)select userid from users where username = @username",maconn);
cmd .parameters.addwithvalue(" @ username",username);
cmd.executenonquery();
maconn.close();
bind();

}

检查这个 [ ^ ]

标签:控件删除事件



分享:

  • 微信
  • QQ好友
  • QQ空间
  • 新浪微博


热门推荐

如何查看.dll文件中编写的代码?(how to view code written in .dll file)

problem hi to all.i have downloaded source co ...

登录 - 使用哈希值检查密码(login - check password with hashed one)

problem this is my code to hash class hashin ...

上传图片时出现问题(problem in uploading images)

problem i want to upload images that will be saved in a f ...

如何使用c#向Bixolon热敏打印机发送命令(How to Send commands to Bixolon thermal printer using c#)

problem first of all , i have searched on goo ...

图像波动问题(image fluctuation problem)

problem i want to know how to remove image fluctuate from ...

LISTVIEW每行的随机ID(LISTVIEW random id for each row)

problem hi, all i want is to generate an id ...

如何创建自定义Web控件......?(How to create a custome web control...)

problem 1) i want to create a class that will inherited f ...

如何管理该代码(how to manage that code)

problem my question is......... we have 3 buttns on page ...

如何删除sysobjects中的列数据但不删除它们的关系(how to delete columns data in sysobjects but not deleted their relations)

problem hello how to delete all system table columns dat ...

异步wcf调用和mantaining会话?(asynchronous wcf call and mantaining session )

problem i have two pages on my website .from page 1 i am ...

通过网络传递序列化数据(Passing serialized data over network)

problem hey, i have a problem with deserializing an objec ...

程序显示按完成时间排序的跑步者,其中一列显示其年龄组内的完成位置(排名)。(Program to display the runners sorted by finish time with a column showing their finish position (ranking) within their age group.)

problem you have a list of runners and their race times a ...

如何调试我的xpath并检查它是否存在一些问题?(How to debug my xpath and to check if there are some problems in it )

problem hi,everyone! now i have a xml file and it looked ...

用户界面设计(User interface Design)

problem hi, i want to design all the user interface scree ...

在ASP.Net中拖放图像(Drag and drop image in ASP.Net)

problem hi, i saw "the drag and drop image i ...

任何人都可以帮助解决'/'应用程序中的服务器错误。(Can any one help dis error Server Error in '/' Application.)

problem hi every one i am upload one .aspx p ...

灰度图像处理(Gray Scale image Processing)

problem hi i want cut the image from pattern the output o ...

如何从javascript调用jsp页面(How to invoke jsp page from javascript)

problem how to invoke jsp page from javascript solution h ...

如何为字符串附加字符。(How can I append characters for a string .)

problem hello all, i have to append lt;stxgt ...

C#Yahoo Messenger注册表观察者(C# Yahoo Messenger registry watcher)

problem hi, my name is nicusor, i have found this code on ...