<title></title>
<style type="text/css">
#divresult ul
{
list-style-type: none;
}
#divresult ul li
{
display: inline;
}
#divresult
{
width: 500px;
border: solid 1px #444;
background-color: #333;
}
</style>
<link href="css/nf.lightbox.css" rel="stylesheet" type="text/css" />
<script src="js/Jquery1.7.js" type="text/javascript"></script>
<script src="js/NFLightBox.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$('#divresult ul a').lightBox();
})
</script>
</head>
<body>
<form id="form1" runat="server">
<div id="divresult" runat="server">
</div>
</form>
</body>
后台:
public partial class WebForm1 : System.Web.UI.Page
{
string id = "0";
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Data();
}
}
private void Data()
{
string str=@"data source=数据库名;initial catalog=自己写的数据库名;user id=连接数据库的名称;password=连接数据库的密码";
SqlConnection con = new SqlConnection(str);
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = "SELECT Img,Img1 FROM Picture";
SqlDataAdapter adpter = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
adpter.Fill(dt);
StringBuilder sb = new StringBuilder();
sb.Append("<div>");
sb.Append("<ul>");
foreach (DataRow row in dt.Rows)
{
string img = row["Img"].ToString();
string img1 = row["Img1"].ToString();
sb.Append("<li>" + "<a href='" + img1 + "'><img src='" + img + "' /></a></li>");
divresult.InnerHtml = sb.ToString();
}
sb.Append("</ul>");
sb.Append("</div>");
}
}