小弟出学 各位大哥帮我看看吧 谢谢datagrid中dropdownlist update数据总有问题
实现代码为vb
datagrid中的dropdownlist 在update数据库的时候总是出错 谢谢哥哥 姐姐帮我看看 本意是想点编辑摁钮后 dropdownlist 绑定某一列出现
'更新的事件
sub mydatagrid_update(sender as object,e as datagridcommandeventargs)
strCon = ConfigurationSettings.AppSettings( "strCon ")
conn = new sqlconnection(strCon)
dim txtid,txtName,txtPassword,txtClsid,txtStyid,txtEmail,txtIdc,txtdate as textbox
txtName = e.item.cells(3).controls(0)
txtPassword = e.item.cells(4).controls(0)
dim txtRl as dropdownlist
txtRl = e.item.cells(5).controls(1)
txtClsid = e.item.cells(6).controls(0)
txtStyid = e.item.cells(7).controls(0)
txtEmail = e.item.cells(8).controls(0)
txtIdc = e.item.cells(9).controls(0)
dim strSql as String
strSql= "Update users Set User_name= ' " & txtName.text & " ',User_password= ' " & txtPassword.text & " ' ,User_roles= " & CInt(txtRl.selecteditem.text) & ",User_clsid= " & Clng(txtClsid.text) & ",User_styid= " & CInt(txtStyid.text) & ",User_email= ' " & txtEmail.text & " ',User_idc= ' " & txtIdc.text & " ' where user_id = " & mydatagrid.datakeys(CInt(e.item.itemindex))
dim cmd as sqlcommand
cmd = new sqlcommand(strSql,conn)
dim exp as exception
try
conn.open()
cmd.executenonquery()
conn.close()
message.text= "操作已成功! "
catch exp
message.text = "更新时出现错误 "
end try
mydatagrid.edititemindex = -1
call binddata()
end sub
在页面中
<form runat= "server ">
<asp:datagrid id = "mydatagrid " headerstyle-backcolor = "#aaaadd " width= "95% "
allowpaging= "true " pagesize= "40 " onpageindexchanged= "mydatagrid_page "
pagerstyle-horizontalalign= "right " pagerstyle-mode= "numericpages "
oneditcommand= "mydatagrid_edit " oncancelcommand= "mydatagrid_cancel " ondeletecommand= "mydatagrid_delete "
onupdatecommand= "mydatagrid_update " datakeyfield= "user_id "
autogeneratecolumns = "false " runat= "server " >
<Columns>
<asp:editcommandcolumn edittext= "编辑 " updatetext= "更新 " canceltext= "取消 " itemstyle-wrap= "false "/>
<asp:buttoncolumn text= "删除 " commandName= "delete " itemstyle-wrap= "false "/>
<asp:boundcolumn headertext= "用户编号 " datafield= "user_id " readonly= "true "/>
<asp:boundcol