html select控件selectedIndex无法赋值!

casoon 2005-08-05 09:04:59
sqlconn.datac()
Dim sql As String = "select * from webadmin where id='" + Request("id") + "'"
Dim cmd As SqlCommand = New SqlCommand(sql, sqlconn.conn)
Dim rs As SqlDataReader
rs = cmd.ExecuteReader
If rs.Read Then
username.Text = rs.Item("username")
selladdress.Value = rs.Item("selladdress")
usertype.Items.FindByText(rs.Item("usertype")).Selected = True
worknum.Value = rs.Item("worknum")
manager.Value = rs.Item("manager")
If Not IsDBNull(rs.Item("code")) Then
code.Value = rs.Item("code")
'city.Items.FindByText(rs.Item("city")).Selected = True
End If
End If
cmd.Cancel()
sqlconn.conn.Close()

执行到usertype.Items.FindByText(rs.Item("usertype")).Selected = True就出错,提示“未将对象引用设置到对象的实例。”,这是怎么回事,要怎么解决,各位大侠帮帮忙!
...全文
444 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
jimu8130 2005-08-05
  • 打赏
  • 举报
回复
html 的select 能这样用么?
noyester 2005-08-05
  • 打赏
  • 举报
回复
你的程序有注入漏洞

id='" + Request("id") + "'"


用参数
casoon 2005-08-05
  • 打赏
  • 举报
回复
xrascal(横刀夺爱)谢谢
casoon 2005-08-05
  • 打赏
  • 举报
回复
select控件中
li = usertype.Items.FindByText("用户类型")
if not li is nothing then
usertype.SelectedIndex = usertype.Items.IndexOf(li)
end if
为什么li总是空呀?
casoon 2005-08-05
  • 打赏
  • 举报
回复
我无法初始化页面为select控件指定的值
huzling 2005-08-05
  • 打赏
  • 举报
回复
不明白是什么!~
问的是什么啊?
暗石绿 2005-08-05
  • 打赏
  • 举报
回复
<%@ Page language="vb" AutoEventWireup="false" debug="true"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >

<html>
<head>
<title>WebForm</title>
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name=vs_defaultClientScript content="JavaScript">
<meta name=vs_targetSchema content="http://schemas.microsoft.com/intellisense/ie5">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<script runat="server" language="vb">
Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

End Sub

Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init

End Sub

Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
dim li as ListItem = nothing
li = usertype.Items.FindByText("用户类型")
if not li is nothing then
usertype.SelectedIndex = usertype.Items.IndexOf(li)
end if

End Sub
</script>
</head>
<body>

<form id="Form1" method="post" runat="server">
<asp:DropDownList id="usertype" runat="server">
<asp:ListItem Selected="True" Value="请选择...">请选择...</asp:ListItem>
<asp:ListItem Value="用户类型">用户类型</asp:ListItem>
</asp:DropDownList>
<asp:Button id="Button1" runat="server" Text="Button" onclick="Button1_Click"/>
</form>

</body>
</html>
casoon 2005-08-05
  • 打赏
  • 举报
回复
usertype是select控件!

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧