日期:2013-09-25  浏览次数:20410 次

@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>

<html>

<script language="C#" runat="server">

    SqlConnection myConnection;

    void Page_Load(Object sender, EventArgs e) {

        myConnection = new SqlConnection("server=(local)\\NetSDK;database=pubs;Trusted_Connection=yes");

        SqlDataAdapter myCommand = new SqlDataAdapter("select * from Titles where type = 'business'", myConnection);

        DataSet ds = new DataSet();
        myCommand.Fill(ds, "Titles");

        MyDataList.DataSource=ds.Tables["Titles"].DefaultView;

        if (!Page.IsPostBack) {
            MyDataList.DataBind();
        }
    }

    void MyDataList_Select(Object sender, EventArgs e) {

        String title = MyDataList.DataKeys[MyDataList.SelectedItem.ItemIndex].ToString();
        SqlDataAdapter myCommand = new SqlDataAdapter("select * from Titles where title_id = '" + title + "'" , myConnection);

        DataSet ds = new DataSet();
        myCommand.Fill(ds, "TitleDetails");

        DataRowView rowview = ds.Tables["TitleDetails"].DefaultView[0];

        DetailsImage.Src = "/quickstart/aspplus/images/title-" + rowview["title_id"] + ".gif";
        DetailsPubId.Text = "<b>Publisher ID: </b>" + rowview["pub_id"].ToString() + "<br>";
        DetailsTitleId.Text = "<b>Title ID: </b>" + rowview["title_id"].ToString() + "<br>";
        DetailsType.Text = "<b>Category: </b>" + rowview["type"].ToString() + "<br>";
        DetailsPrice.Text = "<b>Price: </b> $ " + rowview["price"].ToString() + "<p>";
        PurchaseLink.Text = "<img border='0' src='http://www.163design.net/quickstart/aspplus/images/purchase_book.gif' >";
        PurchaseLink.NavigateUrl ="purchase.aspx?titleid=" + rowview["title_id"].ToString();
        DetailsTitle.Text = rowview["title"].ToString();

        DetailsImage.Visible = true;

        MyDataList.DataBind();
    }

    void MyDataList_ItemCommand(Object sender, DataListCommandEventArgs E) {

        String title = MyDataList.DataKeys[E.Item.ItemIndex].ToString();
        String command = ((LinkButton)E.CommandSource).Text;

        switch(command) {

     &nbs