参考链接:
http://www.cnblogs.com/zfanlong1314/p/3595298.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="_131.WebForm1" %>
<!DOCTYPE html>
<
html
xmlns
=
"http://www.w3.org/1999/xhtml"
>
<
head
runat
=
"server"
>
<
title
></
title
>
</
head
>
<
body
>
<
form
id
=
"form1"
runat
=
"server"
>
<
div
>
<
asp:DropDownList
ID
=
"DropDownList1"
runat
=
"server"
OnSelectedIndexChanged
=
"DropDownList1_SelectedIndexChanged"
AutoPostBack
=
"True"
></
asp:DropDownList
>
<
br
/>
<
asp:Label
ID
=
"Label1"
runat
=
"server"
Text
=
"Name"
></
asp:Label
>
<
asp:TextBox
ID
=
"TextBox1"
runat
=
"server"
></
asp:TextBox
>
<
br
/>
<
asp:Label
ID
=
"Label2"
runat
=
"server"
Text
=
"Age"
></
asp:Label
>
<
asp:TextBox
ID
=
"TextBox2"
runat
=
"server"
></
asp:TextBox
>
<
br
/>
<
asp:Label
ID
=
"Label3"
runat
=
"server"
Text
=
"Remark"
></
asp:Label
>
<
asp:TextBox
ID
=
"TextBox3"
runat
=
"server"
></
asp:TextBox
>
</
div
>
</
form
>
</
body
>
</
html
>
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
using
System;
using
System.Collections.Generic;
using
System.Configuration;
using
System.Data;
using
System.Data.SqlClient;
using
System.Linq;
using
System.Web;
using
System.Web.UI;
using
System.Web.UI.WebControls;
namespace
_131
{
public
partial
class
WebForm1 : System.Web.UI.Page
{
protected
void
Page_Load(
object
sender, EventArgs e)
{
if
(!IsPostBack)
{
string
ConStr = ConfigurationManager.ConnectionStrings[
"strCon"
].ConnectionString;
SqlConnection con =
new
SqlConnection(ConStr);
SqlCommand cmd =
new
SqlCommand(
"select * from tb_sellInfo"
, con);
if
(con.State.Equals(ConnectionState.Closed))
{
con.Open();
}
SqlDataReader sqr = cmd.ExecuteReader();
if
(sqr.HasRows)
{
while
(sqr.Read())
{
DropDownList1.Items.Add(sqr[
"Name"
].ToString());
DropDownList1.DataTextField =
"Name"
;
DropDownList1.DataBind();
}
ListItem li =
new
ListItem(
"请选择"
,
"0"
);
DropDownList1.Items.Insert(0, li);
}
sqr.Close();
con.Close();
}
}
protected
void
DropDownList1_SelectedIndexChanged(
object
sender, EventArgs e)
{
string
sqlcmd =
"select * from tb_sellInfo where Name='"
+ Convert.ToString(DropDownList1.SelectedValue)+
"'"
;
string
ConStr = ConfigurationManager.ConnectionStrings[
"strCon"
].ConnectionString;
SqlConnection con =
new
SqlConnection(ConStr);
con.Open();
SqlCommand cmd =
new
SqlCommand(sqlcmd, con);
SqlDataReader sqr = cmd.ExecuteReader();
sqr.Read();
TextBox1.Text = sqr[
"Name"
].ToString();
TextBox2.Text = sqr[
"Age"
].ToString();
TextBox3.Text = sqr[
"UpdateDate"
].ToString();
sqr.Close();
con.Close();
}
}
}
|
本文转自daniel8294 51CTO博客,原文链接:http://blog.51cto.com/acadia627/1899240
,如需转载请自行联系原作者