注意:我是一名初级 Web 开发人员,对 PHP 有点熟悉。我一直对 ASP.NET 很好奇,想尝试一下。
现在,我正在尝试显示如下表的小型库应用程序:
Title - Author - Status
The Eye of the World - Robert Jordan - Checked Out
The Great Hunt - Robert Jordan - Check Out
The Dragon Reborn - Robert Jordan - Check Out
我创建了一个 DataSet 和一个执行以下查询的 TableAdapter:
SELECT books.SerialNumber, books.Title, books.Author, CheckedOut.cardNumber
FROM books LEFT OUTER JOIN
CheckedOut ON books.SerialNumber = CheckedOut.SerialNumber
我这样做是为了获得 NULL 或 cardNumber 以供下面使用。
这是我主页的当前状态:
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeFile="Browse.aspx.cs" Inherits="_Default" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="SerialNumber,cardNumber" DataSourceID="ObjectDataSource1"
OnRowDataBound="browseMethod"
AllowPaging="True" onselectedindexchanged="GridView1_SelectedIndexChanged">
<Columns>
<asp:BoundField DataField="SerialNumber" HeaderText="SerialNumber"
InsertVisible="False" ReadOnly="True" SortExpression="SerialNumber"
Visible="False" />
<asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
<asp:BoundField DataField="Author" HeaderText="Author"
SortExpression="Author" />
<asp:BoundField DataField="cardNumber" HeaderText="cardNumber"
SortExpression="cardNumber" Visible="False" />
<asp:TemplateField HeaderText="Status">
<ItemTemplate>
<asp:Button ID="Button1" runat="server"
CommandArgument='<%# Eval("cardNumber") %>'
Text="Check Out" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
OldValuesParameterFormatString="original_{0}" SelectMethod="GetLibraryBooks"
TypeName="DataSet1TableAdapters.DataTable1TableAdapter">
</asp:ObjectDataSource>
</asp:Content>
当该行的“cardNumber”值为NULL时,我希望能够将“签出”按钮更改为标签(“签出”)。另外,如何在调用每个按钮时创建一个事件,并获取正确的序列号?