新手问关于DropDownList数据绑定问题

madmangt 2006-04-30 04:45:09
添加了一个dropdownlist控件后 想和hospital里的sickinfo表的"病种名"绑定 下面是代码,页面还是显示数据未绑定。这个是怎么回事?我是新手,别B4...

<%@ Import Namespace= "System.Data.SqlClient" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<script language="C#" runat="server">
protected void Page_Load(Object Src, EventArgs E)
{
{
SqlConnection myConnection = new SqlConnection("server=(local);" + "database =hospital; Trusted_Connection=yes");
SqlDataAdapter myCommand = new SqlDataAdapter("SELECT " + " * FROM SickInfo", myConnection);
DataSet ds =new DataSet();
myCommand.Fill(ds);
DataView source = new DataView(ds.Tables[0]);
DropDownList1.DataSource= source;
DropDownList1.DataBind();
}
}

</script>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
</HEAD>
<body>
<h4><font face="Verdana">病种信息</font>
</h4>
<form id="Form1" method="post" runat="server">
选择病种 <FONT face="宋体">
<asp:dropdownlist id=DropDownList1 runat="server" AutoPostBack="True" DataTextField="病种名" width="120" >
</asp:dropdownlist></FONT></form>
</body>
...全文
132 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
gnhao 2006-04-30
  • 打赏
  • 举报
回复
DropDownList1.DataSource= source;
DropDownList1.DataTextField=病种名的字段名
DropDownList1.DataBind();
你试试吧
眼里进了砂 2006-04-30
  • 打赏
  • 举报
回复
设定this.DropDownList1.DataTextField和this.DropDownList1.DataValueField
deadshot123 2006-04-30
  • 打赏
  • 举报
回复
除非在html代码中用<%#%>来绑定 要不根本不会出现数据已绑定 只有运行时才会绑定上去

Page_Load中代码放到
if(!IsPostBack)
{
}
免得每次页面传递都要绑定

111,093

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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