NOTE: I’m a beginner web developer, somewhat familiar with PHP. I’ve been curious about ASP.NET and wanted to give it a go.
Now, I’m attempting to little library application that displays a table like the following:
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
I have created a DataSet, and a TableAdapter that performs the following query:
SELECT books.SerialNumber, books.Title, books.Author, CheckedOut.cardNumber
FROM books LEFT OUTER JOIN
CheckedOut ON books.SerialNumber = CheckedOut.SerialNumber
I do this so that I can get either NULL or the cardNumber for use below.
Here is the current state of my main page:
<%@ 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>
I want to be able to change the “Check Out” button to a label (“Checked Out”) when the “cardNumber” value for that row is NULL. Also, how can I create an event when each button is called, and grab the correct SerialNumber?
You can create another control label and sets its visibity to false.You have already defied command argument for the button.Give a command name too .
In the gridview_rowCommand callback check for the command Name and do the operations.Set the visibility of button to false there and label to true.ANother option woulb be to enable/disable button as discussed in answer above with disabled style being made in a way such that it looks like a label.For grid view command argument refer the follwoing link :-
http://msdn.microsoft.com/en-us/library/bb907626.aspx