Web程序 如何将用sql语句查到的数据绑定到文本框,下拉框. Web程序 如何将用sql语句查到的数据绑定到文本框,下拉框.各位高手帮帮忙!谢谢! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 DataReader Reader;然后 txtBox.Text = Reader["id"].ToString() <%@ Page Language="C#" %><script runat=server>void Page_Load(Object sender , EventArgs e){ lblMessage.DataBind();}string GetTime() { return DateTime.Now.ToString( "T" );}</Script><html><head><title>SimpleBind.aspx</title></head><body><form Runat="Server"><asp:Label ID="lblMessage" Text='<%# GetTime() %>' Runat="Server" /></form></body></html>===================================================<%@ Page Language="C#" %><%@ Import Namespace="System.Data.SqlClient" %><script runat=server>void Page_Load(Object sender , EventArgs e) { if (! IsPostBack ) { SqlConnection conPubs; SqlCommand cmdSelect; SqlDataReader dtrAuthors; conPubs = new SqlConnection( @"Server=localhost;Integrated Security=SSPI; Database=Pubs" ); conPubs.Open(); cmdSelect = new SqlCommand( "Select au_lname From Authors", conPubs ); dtrAuthors = cmdSelect.ExecuteReader(); dropAuthors.DataSource = dtrAuthors; dropAuthors.DataTextField = "au_lname"; dropAuthors.DataBind(); dtrAuthors.Close(); conPubs.Close(); }}</Script><html><head><title>DropDownList.aspx</title></head><body><form Runat="Server"><asp:DropDownList ID="dropAuthors" Runat="Server" /><asp:Button Text="Pick Author!" Runat="Server" /></form></body></html> //DropDownList1 你所谓的下拉框 try { Conn.Open(); cmd=new SqlCommand("Select cInvCName from InventoryClass where LEN(cInvCCode)=2",Conn); reader=cmd.ExecuteReader(); DropDownList1.Items.Insert(0,new ListItem("请选择大类","0")); DropDownList1.SelectedIndex=0; while(reader.Read()) { ListItem item=new ListItem(reader.GetValue(0).ToString(),reader.GetValue(0).ToString()); DropDownList1.Items.Add(item); } } catch(Exception exc) { this.Response.Write(exc.Message); } finally { reader.Close(); Conn.Close(); }//文本框建议你使用listBox//写法跟上面的是类似的try{cmd=new SqlCommand("select distinct cInvName from Inventory where cInvCCode='"+code+"'",Conn); reader=cmd.ExecuteReader(); while(reader.Read()) { ListItem item=new ListItem(reader.GetValue(0).ToString(),reader.GetValue(0).ToString()); ListBox1.Items.Add(item); } } catch(Exception exc) { this.Response.Write(exc.Message); } finally { reader.Close(); Conn.Close(); }//如果你要在页面加载的时候初始化,你就写道Page_Load里,类似楼上老兄写的 C# VS2008安装部署项目失败 c#+oracle 功能开发求助! javascript脚本中的一个正则表达式的问题 winform中添加一个Picturebox控件, 在picturebox上点击鼠标时怎样能获取该点相对应的主窗口坐标。 游戏服务器开发群.10585468 请给大哥,给我看看,我下面这段程序是错误在那里啊?谢谢! 我问一个基础问题 如何完全定制ListView? 请问C#中如何调用WinIO.dll? 急问!!!!! C#可不可以使用Pointer 大家帮看看,是在是找不到什么地方有问题~ 谢谢了
然后 txtBox.Text = Reader["id"].ToString()
{
lblMessage.DataBind();
}string GetTime() {
return DateTime.Now.ToString( "T" );
}</Script><html>
<head><title>SimpleBind.aspx</title></head>
<body>
<form Runat="Server"><asp:Label
ID="lblMessage"
Text='<%# GetTime() %>'
Runat="Server" /></form>
</body>
</html>===================================================<%@ Page Language="C#" %>
<%@ Import Namespace="System.Data.SqlClient" %><script runat=server>void Page_Load(Object sender , EventArgs e)
{
if (! IsPostBack ) {
SqlConnection conPubs;
SqlCommand cmdSelect;
SqlDataReader dtrAuthors; conPubs = new SqlConnection( @"Server=localhost;Integrated Security=SSPI; Database=Pubs" );
conPubs.Open();
cmdSelect = new SqlCommand( "Select au_lname From Authors", conPubs );
dtrAuthors = cmdSelect.ExecuteReader(); dropAuthors.DataSource = dtrAuthors;
dropAuthors.DataTextField = "au_lname";
dropAuthors.DataBind(); dtrAuthors.Close();
conPubs.Close();
}
}</Script><html>
<head><title>DropDownList.aspx</title></head>
<body>
<form Runat="Server"><asp:DropDownList
ID="dropAuthors"
Runat="Server" /><asp:Button
Text="Pick Author!"
Runat="Server" /></form>
</body>
</html>
try
{
Conn.Open();
cmd=new SqlCommand("Select cInvCName from InventoryClass where LEN(cInvCCode)=2",Conn);
reader=cmd.ExecuteReader();
DropDownList1.Items.Insert(0,new ListItem("请选择大类","0"));
DropDownList1.SelectedIndex=0;
while(reader.Read())
{
ListItem item=new ListItem(reader.GetValue(0).ToString(),reader.GetValue(0).ToString());
DropDownList1.Items.Add(item);
}
}
catch(Exception exc)
{
this.Response.Write(exc.Message);
}
finally
{
reader.Close();
Conn.Close();
}
//文本框建议你使用listBox
//写法跟上面的是类似的
try
{
cmd=new SqlCommand("select distinct cInvName from Inventory where cInvCCode='"+code+"'",Conn);
reader=cmd.ExecuteReader();
while(reader.Read())
{
ListItem item=new ListItem(reader.GetValue(0).ToString(),reader.GetValue(0).ToString());
ListBox1.Items.Add(item);
}
}
catch(Exception exc)
{
this.Response.Write(exc.Message);
}
finally
{
reader.Close();
Conn.Close();
}//如果你要在页面加载的时候初始化,你就写道Page_Load里,类似楼上老兄写的