首先,我的程序運行良好,它按照我希望的方式執行,我只是希望避免刷新。從更新面板中的formview更新Gridview(第2部分)
所以我嘗試了幾種不同的解決方案,但是我的更新面板似乎還沒有正常工作。我有2個gridviews和2個formviews。我嘗試添加觸發器,在方法上調用updatepanel1.update(),在每個文本框中添加autopostback ='true'等等。我將它們全部放在我的程序中,試圖縮小實際上讓我看到gridview的新增功能從formview上的插入記錄而不刷新頁面。如果有人仍然可以告訴我我錯過了什麼,那會很棒。我只是要複製我的整個2個文件。
代碼背後:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace PO_1_5_15
{
public partial class _Webform : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (FormView1.CurrentMode == FormViewMode.Edit)
{
LinkButton lb = (LinkButton)FormView1.FindControl("UpdateButton");
ScriptManager.GetCurrent(Page).RegisterPostBackControl(lb);
}
if (FormView1.CurrentMode == FormViewMode.Insert)
{
LinkButton lb2 = (LinkButton)FormView1.FindControl("InsertButton");
ScriptManager.GetCurrent(Page).RegisterPostBackControl(lb2);
}
if (FormView2.CurrentMode == FormViewMode.Edit)
{
LinkButton lb3 = (LinkButton)FormView1.FindControl("UpdateButton");
ScriptManager.GetCurrent(Page).RegisterPostBackControl(lb3);
}
if (FormView2.CurrentMode == FormViewMode.Insert)
{
LinkButton lb4 = (LinkButton)FormView1.FindControl("InsertButton");
ScriptManager.GetCurrent(Page).RegisterPostBackControl(lb4);
}
GridView1.DataBind();
GridView1.Visible = true;
}
protected void FormsView1_ItemInserted(object sender, DetailsViewInsertedEventArgs e)
{
GridView1.DataBind();
UpdatePanel1.Update();
}
protected void FormsView1_ItemDeleted(object sender, DetailsViewDeletedEventArgs e)
{
GridView1.DataBind();
UpdatePanel1.Update();
}
protected void FormsView1_ItemUpdated(object sender, DetailsViewUpdatedEventArgs e)
{
GridView1.DataBind();
FormView1.Visible = true;
GridView1.Visible = true;
UpdatePanel1.Update();
}
protected void GridView1_OnSelectedIndexChanged(object sender, EventArgs e)
{
FormView1.DataBind();
FormView1.Visible = true;
GridView1.Visible = false;
UpdatePanel1.Update();
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
UpdatePanel1.Update();
}
protected void FormView2_PageIndexChanging(object sender, FormViewPageEventArgs e)
{
UpdatePanel1.Update();
}
}
}
HTML標記:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Webform.aspx.cs" Inherits="PO_1_5_15._Webform" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager runat="server" ID="sm1"></asp:ScriptManager>
<div>
<br />
<asp:UpdatePanel runat="server" UpdateMode="Always" ID="UpdatePanel1">
<ContentTemplate >
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="PO_ID" DataSourceID="SqlDataSource1" EnableModelValidation="True" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="4" ForeColor="Black" GridLines="Horizontal">
<Columns>
<asp:CommandField ShowSelectButton="True" />
<asp:BoundField DataField="PO_ID" HeaderText="PO_ID" SortExpression="PO_ID" />
<asp:BoundField DataField="PO_Title" HeaderText="PO_Title" SortExpression="PO_Title" />
<asp:BoundField DataField="Date_Received" HeaderText="Date_Received" SortExpression="Date_Received" />
<asp:BoundField DataField="Date_Completed" HeaderText="Date_Completed" SortExpression="Date_Completed" />
<asp:BoundField DataField="Username" HeaderText="Username" SortExpression="Username" />
<asp:BoundField DataField="PO_Note" HeaderText="PO_Note" SortExpression="PO_Note" />
<asp:BoundField DataField="UserDate" HeaderText="UserDate" SortExpression="UserDate" />
</Columns>
<FooterStyle BackColor="#CCCC99" ForeColor="Black" />
<HeaderStyle BackColor="#333333" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="White" ForeColor="Black" HorizontalAlign="Right" />
<SelectedRowStyle BackColor="#CC3333" Font-Bold="True" ForeColor="White" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:Test_DatabaseConnectionString %>" SelectCommand="SELECT [PO_ID], [PO_Title], [Date_Received], [Date_Completed], [Username], [PO_Note], [UserDate] FROM [PO_Table]"></asp:SqlDataSource>
<asp:FormView ID="FormView1" runat="server" DataKeyNames="PO_AutoID" DataSourceID="SqlDataSource2" EnableModelValidation="True" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="4" ForeColor="Black" GridLines="Horizontal">
<EditItemTemplate>
PO_AutoID:
<asp:Label ID="PO_AutoIDLabel1" runat="server" Text='<%# Eval("PO_AutoID") %>' />
<br />
PO_ID:
<asp:TextBox ID="PO_IDTextBox" runat="server" Text='<%# Bind("PO_ID") %>' AutoPostBack="True" />
<br />
PO_Title:
<asp:TextBox ID="PO_TitleTextBox" runat="server" Text='<%# Bind("PO_Title") %>' AutoPostBack="True"/>
<br />
Date_Received:
<asp:TextBox ID="Date_ReceivedTextBox" runat="server" Text='<%# Bind("Date_Received") %>' AutoPostBack="True"/>
<br />
Date_Completed:
<asp:TextBox ID="Date_CompletedTextBox" runat="server" Text='<%# Bind("Date_Completed") %>' AutoPostBack="True"/>
<br />
PO_Note:
<asp:TextBox ID="PO_NoteTextBox" runat="server" Text='<%# Bind("PO_Note") %>' AutoPostBack="True"/>
<br />
<asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update" Text="Update" />
<asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</EditItemTemplate>
<EditRowStyle BackColor="#CC3333" Font-Bold="True" ForeColor="White" />
<FooterStyle BackColor="#CCCC99" ForeColor="Black" />
<HeaderStyle BackColor="#333333" Font-Bold="True" ForeColor="White" />
<InsertItemTemplate>
PO_ID:
<asp:TextBox ID="PO_IDTextBox" runat="server" Text='<%# Bind("PO_ID") %>' AutoPostBack="True"/>
<br />
PO_Title:
<asp:TextBox ID="PO_TitleTextBox" runat="server" Text='<%# Bind("PO_Title") %>' AutoPostBack="True"/>
<br />
Date_Received:
<asp:TextBox ID="Date_ReceivedTextBox" runat="server" Text='<%# Bind("Date_Received") %>' AutoPostBack="True"/>
<br />
Date_Completed:
<asp:TextBox ID="Date_CompletedTextBox" runat="server" Text='<%# Bind("Date_Completed") %>' AutoPostBack="True"/>
<br />
PO_Note:
<asp:TextBox ID="PO_NoteTextBox" runat="server" Text='<%# Bind("PO_Note") %>' AutoPostBack="True"/>
<br />
<asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert" Text="Insert" />
<asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</InsertItemTemplate>
<ItemTemplate>
PO_AutoID:
<asp:Label ID="PO_AutoIDLabel" runat="server" Text='<%# Eval("PO_AutoID") %>' />
<br />
PO_ID:
<asp:Label ID="PO_IDLabel" runat="server" Text='<%# Bind("PO_ID") %>' />
<br />
PO_Title:
<asp:Label ID="PO_TitleLabel" runat="server" Text='<%# Bind("PO_Title") %>' />
<br />
Date_Received:
<asp:Label ID="Date_ReceivedLabel" runat="server" Text='<%# Bind("Date_Received") %>' />
<br />
Date_Completed:
<asp:Label ID="Date_CompletedLabel" runat="server" Text='<%# Bind("Date_Completed") %>' />
<br />
Username:
<asp:Label ID="UsernameLabel" runat="server" Text='<%# Bind("Username") %>' />
<br />
UserDate:
<asp:Label ID="UserDateLabel" runat="server" Text='<%# Bind("UserDate") %>' />
<br />
PO_Note:
<asp:Label ID="PO_NoteLabel" runat="server" Text='<%# Bind("PO_Note") %>' />
<br />
<asp:LinkButton ID="EditButton" runat="server" CausesValidation="False" CommandName="Edit" Text="Edit" />
<asp:LinkButton ID="DeleteButton" runat="server" CausesValidation="False" CommandName="Delete" Text="Delete" />
<asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" CommandName="New" Text="New" />
</ItemTemplate>
<PagerStyle BackColor="White" ForeColor="Black" HorizontalAlign="Right" />
</asp:FormView>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:Test_DatabaseConnectionString %>" DeleteCommand="DeletePO" DeleteCommandType="StoredProcedure" InsertCommand="InsertPO" InsertCommandType="StoredProcedure" SelectCommand="SELECT * FROM [PO_Table] WHERE ([PO_ID] = @PO_ID)" UpdateCommand="UpdatePO" UpdateCommandType="StoredProcedure">
<DeleteParameters>
<asp:Parameter Name="PO_AutoID" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="PO_ID" Type="Int32" />
<asp:Parameter Name="PO_Title" Type="String" />
<asp:Parameter Name="Date_Received" Type="DateTime" />
<asp:Parameter Name="Date_Completed" Type="DateTime" />
<asp:Parameter Name="PO_Note" Type="String" />
<asp:Parameter Name="Username" Type="String" />
<asp:Parameter Name="UserDate" Type="DateTime" />
</InsertParameters>
<SelectParameters>
<asp:ControlParameter ControlID="GridView1" Name="PO_ID" PropertyName="SelectedValue" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="PO_ID" Type="Int32" />
<asp:Parameter Name="PO_Title" Type="String" />
<asp:Parameter Name="Date_Received" Type="DateTime" />
<asp:Parameter Name="Date_Completed" Type="DateTime" />
<asp:Parameter Name="UserDate" Type="DateTime" />
<asp:Parameter Name="Username" Type="String" />
<asp:Parameter Name="PO_Note" Type="String" />
<asp:Parameter Name="PO_AutoID" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
<asp:GridView ID="GridView2" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="Task_AutoID" DataSourceID="SqlDataSource3" EnableModelValidation="True" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="4" ForeColor="Black" GridLines="Horizontal">
<Columns>
<asp:CommandField ShowSelectButton="True" />
<asp:BoundField DataField="Task_AutoID" HeaderText="Task_AutoID" InsertVisible="False" ReadOnly="True" SortExpression="Task_AutoID" />
<asp:BoundField DataField="PO_AutoID" HeaderText="PO_AutoID" SortExpression="PO_AutoID" />
<asp:BoundField DataField="PO_ID" HeaderText="PO_ID" SortExpression="PO_ID" />
<asp:BoundField DataField="Task_Title" HeaderText="Task_Title" SortExpression="Task_Title" />
<asp:BoundField DataField="Username" HeaderText="Username" SortExpression="Username" />
<asp:BoundField DataField="UserDate" HeaderText="UserDate" SortExpression="UserDate" />
<asp:BoundField DataField="Cost" HeaderText="Cost" SortExpression="Cost" />
<asp:BoundField DataField="_Status" HeaderText="_Status" SortExpression="_Status" />
<asp:BoundField DataField="Invoice_Date" HeaderText="Invoice_Date" SortExpression="Invoice_Date" />
<asp:BoundField DataField="Paid_Date" HeaderText="Paid_Date" SortExpression="Paid_Date" />
<asp:BoundField DataField="Task_Note" HeaderText="Task_Note" SortExpression="Task_Note" />
</Columns>
<FooterStyle BackColor="#CCCC99" ForeColor="Black" />
<HeaderStyle BackColor="#333333" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="White" ForeColor="Black" HorizontalAlign="Right" />
<SelectedRowStyle BackColor="#CC3333" Font-Bold="True" ForeColor="White" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:Test_DatabaseConnectionString %>" SelectCommand="SELECT * FROM [Task]"></asp:SqlDataSource>
<br />
<asp:FormView ID="FormView2" runat="server" DataKeyNames="Task_AutoID" DataSourceID="SqlDataSource4" EnableModelValidation="True" OnPageIndexChanging="FormView2_PageIndexChanging" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="4" ForeColor="Black" GridLines="Horizontal">
<EditItemTemplate>
Task_AutoID:
<asp:Label ID="Task_AutoIDLabel1" runat="server" Text='<%# Eval("Task_AutoID") %>' />
<br />
PO_ID:
<asp:TextBox ID="PO_IDTextBox" runat="server" Text='<%# Bind("PO_ID") %>' AutoPostBack="True"/>
<br />
Task_Title:
<asp:TextBox ID="Task_TitleTextBox" runat="server" Text='<%# Bind("Task_Title") %>' AutoPostBack="True"/>
<br />
Cost:
<asp:TextBox ID="CostTextBox" runat="server" Text='<%# Bind("Cost") %>' AutoPostBack="True"/>
<br />
_Status:
<asp:DropDownList ID="DropDownList1" runat="server" SelectedValue='<%# Bind("_Status") %>' AutoPostBack="True">
<asp:ListItem>One</asp:ListItem>
<asp:ListItem>Two</asp:ListItem>
<asp:ListItem>Three</asp:ListItem>
</asp:DropDownList>
<br />
Invoice_Date:
<asp:TextBox ID="Invoice_DateTextBox" runat="server" Text='<%# Bind("Invoice_Date") %>' AutoPostBack="True"/>
<br />
Paid_Date:
<asp:TextBox ID="Paid_DateTextBox" runat="server" Text='<%# Bind("Paid_Date") %>' AutoPostBack="True"/>
<br />
Task_Note:
<asp:TextBox ID="Task_NoteTextBox" runat="server" Text='<%# Bind("Task_Note") %>' AutoPostBack="True"/>
<br />
<asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update" Text="Update" />
<asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</EditItemTemplate>
<EditRowStyle BackColor="#CC3333" Font-Bold="True" ForeColor="White" />
<FooterStyle BackColor="#CCCC99" ForeColor="Black" />
<HeaderStyle BackColor="#333333" Font-Bold="True" ForeColor="White" />
<InsertItemTemplate>
PO_ID:
<asp:TextBox ID="PO_IDTextBox" runat="server" Text='<%# Bind("PO_ID") %>' AutoPostBack="True"/>
<br />
Task_Title:
<asp:TextBox ID="Task_TitleTextBox" runat="server" Text='<%# Bind("Task_Title") %>' AutoPostBack="True"/>
<br />
Cost:
<asp:TextBox ID="CostTextBox" runat="server" Text='<%# Bind("Cost") %>' AutoPostBack="True"/>
<br />
_Status:
<asp:DropDownList ID="DropDownList1" runat="server" SelectedValue='<%# Bind("_Status") %>' AutoPostBack="True">
<asp:ListItem>One</asp:ListItem>
<asp:ListItem>Two</asp:ListItem>
<asp:ListItem>Three</asp:ListItem>
</asp:DropDownList>
<br />
Invoice_Date:
<asp:TextBox ID="Invoice_DateTextBox" runat="server" Text='<%# Bind("Invoice_Date") %>' AutoPostBack="True"/>
<br />
Paid_Date:
<asp:TextBox ID="Paid_DateTextBox" runat="server" Text='<%# Bind("Paid_Date") %>' AutoPostBack="True"/>
<br />
Task_Note:
<asp:TextBox ID="Task_NoteTextBox" runat="server" Text='<%# Bind("Task_Note") %>' AutoPostBack="True"/>
<br />
<asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert" Text="Insert" />
<asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</InsertItemTemplate>
<ItemTemplate>
Task_AutoID:
<asp:Label ID="Task_AutoIDLabel" runat="server" Text='<%# Eval("Task_AutoID") %>' />
<br />
PO_AutoID:
<asp:Label ID="PO_AutoIDLabel" runat="server" Text='<%# Bind("PO_AutoID") %>' />
<br />
PO_ID:
<asp:Label ID="PO_IDLabel" runat="server" Text='<%# Bind("PO_ID") %>' />
<br />
Task_Title:
<asp:Label ID="Task_TitleLabel" runat="server" Text='<%# Bind("Task_Title") %>' />
<br />
Username:
<asp:Label ID="UsernameLabel" runat="server" Text='<%# Bind("Username") %>' />
<br />
UserDate:
<asp:Label ID="UserDateLabel" runat="server" Text='<%# Bind("UserDate") %>' />
<br />
Cost:
<asp:Label ID="CostLabel" runat="server" Text='<%# Bind("Cost") %>' />
<br />
_Status:
<asp:Label ID="_StatusLabel" runat="server" Text='<%# Bind("_Status") %>' />
<br />
Invoice_Date:
<asp:Label ID="Invoice_DateLabel" runat="server" Text='<%# Bind("Invoice_Date") %>' />
<br />
Paid_Date:
<asp:Label ID="Paid_DateLabel" runat="server" Text='<%# Bind("Paid_Date") %>' />
<br />
Task_Note:
<asp:Label ID="Task_NoteLabel" runat="server" Text='<%# Bind("Task_Note") %>' />
<br />
<asp:LinkButton ID="EditButton" runat="server" CausesValidation="False" CommandName="Edit" Text="Edit" />
<asp:LinkButton ID="DeleteButton" runat="server" CausesValidation="False" CommandName="Delete" Text="Delete" />
<asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" CommandName="New" Text="New" />
</ItemTemplate>
<PagerStyle BackColor="White" ForeColor="Black" HorizontalAlign="Right" />
</asp:FormView>
<asp:SqlDataSource ID="SqlDataSource4" runat="server" ConnectionString="<%$ ConnectionStrings:Test_DatabaseConnectionString %>" DeleteCommand="DELETE FROM [Task] WHERE [Task_AutoID] = @Task_AutoID" InsertCommand="INSERT INTO [Task] ([PO_AutoID], [PO_ID], [Task_Title], [Username], [UserDate], [Cost], [_Status], [Invoice_Date], [Paid_Date], [Task_Note]) VALUES (@PO_AutoID, @PO_ID, @Task_Title, SUSER_SNAME(), SYSDATETIME(), @Cost, @_Status, @Invoice_Date, @Paid_Date, @Task_Note);
" SelectCommand="SELECT * FROM [Task] WHERE ([Task_AutoID] = @Task_AutoID)" UpdateCommand="UPDATE [Task] SET [PO_AutoID] = @PO_AutoID, [PO_ID] = @PO_ID, [Task_Title] = @Task_Title, [Username] = SUSER_SNAME(), [UserDate] = SYSDATETIME(), [Cost] = @Cost, [_Status] = @_Status, [Invoice_Date] = @Invoice_Date, [Paid_Date] = @Paid_Date, [Task_Note] = @Task_Note WHERE [Task_AutoID] = @Task_AutoID
">
<DeleteParameters>
<asp:Parameter Name="Task_AutoID" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="PO_AutoID" Type="Int32" />
<asp:Parameter Name="PO_ID" Type="Int32" />
<asp:Parameter Name="Task_Title" Type="String" />
<asp:Parameter Name="Cost" Type="Decimal" />
<asp:Parameter Name="_Status" />
<asp:Parameter Name="Invoice_Date" Type="DateTime" />
<asp:Parameter Name="Paid_Date" Type="DateTime" />
<asp:Parameter Name="Task_Note" Type="String" />
</InsertParameters>
<SelectParameters>
<asp:ControlParameter ControlID="GridView2" Name="Task_AutoID" PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="PO_AutoID" Type="Int32" />
<asp:Parameter Name="PO_ID" Type="Int32" />
<asp:Parameter Name="Task_Title" Type="String" />
<asp:Parameter Name="Cost" Type="Decimal" />
<asp:Parameter Name="_Status" />
<asp:Parameter Name="Invoice_Date" Type="DateTime" />
<asp:Parameter Name="Paid_Date" Type="DateTime" />
<asp:Parameter Name="Task_Note" Type="String" />
<asp:Parameter Name="Task_AutoID" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
<br />
<br />
<br />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="FormView1" EventName="DataBound" />
<asp:AsyncPostBackTrigger ControlID="FormView1" EventName="DataBinding" />
<asp:AsyncPostBackTrigger ControlID="FormView1" EventName="Disposed" />
<asp:AsyncPostBackTrigger ControlID="FormView1" EventName="Init" />
<asp:AsyncPostBackTrigger ControlID="FormView1" EventName="ItemCommand" />
<asp:AsyncPostBackTrigger ControlID="FormView1" EventName="ItemCreated" />
<asp:AsyncPostBackTrigger ControlID="FormView1" EventName="ItemDeleted" />
<asp:AsyncPostBackTrigger ControlID="FormView1" EventName="ItemDeleting" />
<asp:AsyncPostBackTrigger ControlID="FormView1" EventName="ItemInserted" />
<asp:AsyncPostBackTrigger ControlID="FormView1" EventName="ItemInserting" />
<asp:AsyncPostBackTrigger ControlID="FormView1" EventName="ItemUpdated" />
<asp:AsyncPostBackTrigger ControlID="FormView1" EventName="ItemUpdating" />
<asp:AsyncPostBackTrigger ControlID="FormView1" EventName="Load" />
<asp:AsyncPostBackTrigger ControlID="FormView1" EventName="ModeChanged" />
<asp:AsyncPostBackTrigger ControlID="FormView1" EventName="ModeChanging" />
<asp:AsyncPostBackTrigger ControlID="FormView1" EventName="PageIndexChanged" />
<asp:AsyncPostBackTrigger ControlID="FormView1" EventName="PageIndexChanging" />
<asp:AsyncPostBackTrigger ControlID="FormView1" EventName="PreRender" />
<asp:AsyncPostBackTrigger ControlID="FormView1" EventName="Unload" />
<asp:AsyncPostBackTrigger ControlID="FormView2" EventName="DataBinding" />
<asp:AsyncPostBackTrigger ControlID="FormView2" EventName="DataBound" />
<asp:AsyncPostBackTrigger ControlID="FormView2" EventName="Disposed" />
<asp:AsyncPostBackTrigger ControlID="FormView2" EventName="Init" />
<asp:AsyncPostBackTrigger ControlID="FormView2" EventName="ItemCommand" />
<asp:AsyncPostBackTrigger ControlID="FormView2" EventName="ItemCreated" />
<asp:AsyncPostBackTrigger ControlID="FormView2" EventName="ItemDeleted" />
<asp:AsyncPostBackTrigger ControlID="FormView2" EventName="ItemDeleting" />
<asp:AsyncPostBackTrigger ControlID="FormView2" EventName="ItemInserted" />
<asp:AsyncPostBackTrigger ControlID="FormView2" EventName="ItemInserting" />
<asp:AsyncPostBackTrigger ControlID="FormView2" EventName="ItemUpdated" />
<asp:AsyncPostBackTrigger ControlID="FormView2" EventName="ItemUpdating" />
<asp:AsyncPostBackTrigger ControlID="FormView2" EventName="Load" />
<asp:AsyncPostBackTrigger ControlID="FormView2" EventName="ModeChanged" />
<asp:AsyncPostBackTrigger ControlID="FormView2" EventName="ModeChanging" />
<asp:AsyncPostBackTrigger ControlID="FormView2" EventName="PageIndexChanged" />
<asp:AsyncPostBackTrigger ControlID="FormView2" EventName="PageIndexChanging" />
<asp:AsyncPostBackTrigger ControlID="FormView2" EventName="PreRender" />
<asp:AsyncPostBackTrigger ControlID="GridView1" EventName="Unload" />
</Triggers>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>
是的,我知道我過度使用代碼,但我知道有幾種技術用於實現更新面板。我所擁有的唯一回復來自「狀態」的下拉菜單。那麼我應該在哪裏使用autopostback?在鏈接按鈕上沒有選項,例如更新,插入和刪除。我是否可以將所有控件包裝在一個更新面板中?我是否使用「UpdatePanel1.Update();」在任何方法或多種方法上,或者沒有必要? –
我的意思是在我的第一句話中添加一些無用的代碼當然是沒有效率的。但我只是縮小了可能性。無論如何,是的,我需要爲我的2個gridviews和2個formviews更新面板嗎?我試過1,但那不起作用? –
你不需要任何更新面板來更新gridviews,但由於你沒有通過gridview進行編輯,所以在成功插入或通過formviews更新後需要重新設置griviews。使用updatepanel只會讓頁面的一部分傳回給瀏覽器,它與更新gridview無關。 – fnostro