日期:2009-09-29  浏览次数:20440 次

@ 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='/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 =