001 | <%@ Page Language="C#" AutoEventWireup="false" CodeFile="Default.aspx.cs" |
002 | Inherits="_Default" %> |
006 | < head id = "Head1" runat = "server" > |
007 | < title >GridView DetailsView Master-Details (Insert)</ title > |
010 | < form id = "form1" runat = "server" > |
011 | < b >Choose a state: </ b > |
012 | < asp:DropDownList ID = "DropDownList1" DataSourceID = "SqlDataSource1" |
013 | AutoPostBack = "True" DataTextField = "state" runat = "server" |
014 | OnSelectedIndexChanged = "DropDownList1_SelectedIndexChanged" /> |
015 | < asp:SqlDataSource ID = "SqlDataSource1" runat = "server" |
016 | SelectCommand = "SELECT DISTINCT state FROM authors" |
017 | ConnectionString="<%$ ConnectionStrings:ConnectionString1 %>" |
018 | ProviderName="<%$ ConnectionStrings:ConnectionString1.ProviderName %>" /> |
019 | < table bgcolor = "lightgreen" > |
023 | < asp:GridView ID = "GridView1" AllowSorting = "True" AllowPaging = "True" |
024 | runat = "server" DataSourceID = "SqlDataSource2" DataKeyNames = "au_id" |
025 | AutoGenerateColumns = "False" Width = "500px" SelectedIndex = "0" |
026 | OnSelectedIndexChanged = "GridView1_SelectedIndexChanged" |
027 | OnPageIndexChanged = "GridView1_PageIndexChanged" |
028 | OnRowDeleted = "GridView1_RowDeleted" OnSorted = "GridView1_Sorted" > |
030 | < asp:CommandField ShowSelectButton = "true" ShowDeleteButton = "true" /> |
031 | < asp:BoundField DataField = "au_id" HeaderText = "au_id" ReadOnly = "True" |
032 | SortExpression = "au_id" /> |
033 | < asp:BoundField DataField = "au_lname" HeaderText = "au_lname" |
034 | SortExpression = "au_lname" /> |
035 | < asp:BoundField DataField = "au_fname" HeaderText = "au_fname" |
036 | SortExpression = "au_fname" /> |
037 | < asp:BoundField DataField = "state" HeaderText = "state" |
038 | SortExpression = "state" /> |
042 | < asp:SqlDataSource ID = "SqlDataSource2" runat = "server" |
043 | SelectCommand = "SELECT au_id, au_lname, au_fname, state |
044 | FROM authors where state=@state" |
045 | DeleteCommand = "DELETE FROM authors WHERE au_id = @au_id" |
046 | ConnectionString="<%$ ConnectionStrings:ConnectionString2 %>" |
047 | ProviderName="<%$ ConnectionStrings:ConnectionString2.ProviderName %>" > |
049 | < asp:ControlParameter ControlID = "DropDownList1" Name = "state" |
050 | PropertyName = "SelectedValue" Type = "String" /> |
056 | < asp:DetailsView AutoGenerateRows = "False" DataKeyNames = "au_id" |
057 | DataSourceID = "SqlDataSource3" HeaderText = "Author Details" |
058 | ID = "DetailsView1" runat = "server" Width = "275px" |
059 | OnItemUpdated = "DetailsView1_ItemUpdated" |
060 | OnItemInserted = "DetailsView1_ItemInserted" |
061 | OnDataBound = "DetailsView1_DataBound" > |
064 | < asp:BoundField DataField = "au_id" HeaderText = "au_id" ReadOnly = "True" |
065 | SortExpression = "au_id" /> |
066 | < asp:BoundField DataField = "au_lname" HeaderText = "au_lname" |
067 | SortExpression = "au_lname" /> |
068 | < asp:BoundField DataField = "au_fname" HeaderText = "au_fname" |
069 | SortExpression = "au_fname" /> |
070 | < asp:BoundField DataField = "phone" HeaderText = "phone" |
071 | SortExpression = "phone" /> |
072 | < asp:BoundField DataField = "address" HeaderText = "address" |
073 | SortExpression = "address" /> |
074 | < asp:BoundField DataField = "city" HeaderText = "city" |
075 | SortExpression = "city" /> |
076 | < asp:BoundField DataField = "state" HeaderText = "state" |
077 | SortExpression = "state" /> |
078 | < asp:BoundField DataField = "zip" HeaderText = "zip" |
079 | SortExpression = "zip" /> |
080 | < asp:CheckBoxField DataField = "contract" |
081 | HeaderText = "contract" SortExpression = "contract" /> |
082 | < asp:CommandField ShowEditButton = "True" ShowInsertButton = "True" /> |
086 | < asp:SqlDataSource ID = "SqlDataSource3" runat = "server" |
087 | SelectCommand = "SELECT au_id, au_lname, au_fname, phone, address, |
088 | city, state, zip, contract FROM authors WHERE au_id=@au_id" |
089 | UpdateCommand = "UPDATE authors SET au_lname = @au_lname, au_fname = @au_fname, |
090 | phone = @phone, address = @address, city = @city, state = @state, zip = @zip, |
091 | contract = @contract WHERE au_id=@au_id" |
092 | InsertCommand = "INSERT INTO authors ( au_id, au_lname, au_fname, phone, |
093 | address, city, state, zip, contract) VALUES( @au_id, @au_lname, @au_fname, |
094 | @phone, @address, @city, @state, @zip, @contract )" |
095 | ConnectionString="<%$ ConnectionStrings:ConnectionString3 %>" |
096 | ProviderName="<%$ ConnectionStrings:ConnectionString3.ProviderName %>" > |
099 | < asp:ControlParameter ControlID = "GridView1" Name = "au_id" |
100 | PropertyName = "SelectedValue" Type = "String" /> |
104 | < asp:Parameter Name = "au_id" Type = "Int16" /> |
105 | < asp:Parameter Name = "au_lname" Type = "String" /> |
106 | < asp:Parameter Name = "au_fname" Type = "String" /> |
107 | < asp:Parameter Name = "phone" Type = "String" /> |
108 | < asp:Parameter Name = "address" Type = "String" /> |
109 | < asp:Parameter Name = "city" Type = "String" /> |
110 | < asp:Parameter Name = "state" Type = "String" /> |
111 | < asp:Parameter Name = "zip" Type = "String" /> |
112 | < asp:Parameter Name = "contract" Type = "Boolean" /> |
116 | < asp:Parameter Name = "au_id" Type = "Int16" /> |
117 | < asp:Parameter Name = "au_lname" Type = "String" /> |
118 | < asp:Parameter Name = "au_fname" Type = "String" /> |
119 | < asp:Parameter Name = "phone" Type = "String" /> |
120 | < asp:Parameter Name = "address" Type = "String" /> |
121 | < asp:Parameter Name = "city" Type = "String" /> |
122 | < asp:Parameter Name = "state" Type = "String" /> |
123 | < asp:Parameter Name = "zip" Type = "String" /> |
124 | < asp:Parameter Name = "contract" Type = "Boolean" /> |
131 | < asp:Label ID = "ErrorMessageLabel" EnableViewState = "false" runat = "server" /> |
|