我設立HealthMonitoring
,我寫了幾頁來管理事件日誌。如何找到這些頁面的DetailsView抱選擇GridView的行
我有一頁有GridView
,另一頁有DetailsView
。 GridView
在每行上都有一個模板按鈕,並帶有一個onClick事件,該事件可加載第二頁,其上面有DetailsView
。
我想要做的是;當我單擊GridView
上的模板按鈕時,它將加載第二頁與DetailsView
,並將GridView
中的特定記錄插入到DetailsView
表中。
DetailsView
必須啓用分頁功能。我被卡住試圖找出哪個頁面索引加載GridView
正確的記錄。目前它只會加載第一頁索引,然後點擊我需要的記錄旁邊。
如果沒有啓用分頁功能,我可以讀取我的2個全局變量,然後將正確的記錄加載到DetailsView
表中,但啓用分頁功能後,我不知道如何去做。
在GridView
頁:
protected void Details1_ButtonClick(object sender, EventArgs e)
{
//I set 2 global variables here of the selected EventId and
//Details to read when the next page loads
Response.Redirect("ErrorDetails.aspx");
}
在DetailsView
頁面。
protected void Page_Load(object sender, EventArgs e)
{
//without paging I can set the SqlDataSource1.SelectCommand to select
//the correct record using one of the global variables
}
我曾嘗試使用DetailsView1_PageIndexChanged
,DetailsView1_Load
和Page_Load
獲得第一行中的值,但由於某些原因,它是永諾後面的頁面。變量總是顯示加載前一頁的ID。我將嘗試跟蹤刪除記錄的頁面,但它也不起作用。
這是ErrorDetails.aspx數據源和DetailsView:
<asp:SqlDataSource
ID="SqlDataSource1"
runat="server"
ConnectionString="<%$ ConnectionStrings:DefaultConnection %>"
ProviderName="<%$ ConnectionStrings:DefaultConnection.ProviderName %>">
<DeleteParameters>
<asp:Parameter Name="EventId" />
</DeleteParameters>
</asp:SqlDataSource>
<asp:DetailsView ID="DetailsView1" runat="server" Height="50px" Width="125px" DataSourceID="SqlDataSource1" DataKeyNames="EventId" AutoGenerateRows="False" OnItemDeleted="DetailsView1_ItemDeleted" OnItemDeleting="DetailsView1_ItemDeleting" AllowPaging="True" OnLoad="DetailsView1_Load" OnPageIndexChanged="DetailsView1_PageIndexChanged" OnPageIndexChanging="DetailsView1_PageIndexChanging">
<AlternatingRowStyle CssClass="alt" />
<Fields>
<asp:CommandField ShowDeleteButton="True" />
<asp:BoundField DataField="EventId" HeaderText="EventId" />
<asp:BoundField DataField="EventTimeUtc" HeaderText="EventTimeUtc" />
<asp:BoundField DataField="EventTime" HeaderText="EventTime" />
<asp:BoundField DataField="EventType" HeaderText="EventType" />
<asp:BoundField DataField="EventSequence" HeaderText="EventSequence" />
<asp:BoundField DataField="EventOccurrence" HeaderText="EventOccurrence" />
<asp:BoundField DataField="EventCode" HeaderText="EventCode" />
<asp:BoundField DataField="EventDetailCode" HeaderText="EventDetailCode" />
<asp:BoundField DataField="Message" HeaderText="Message" />
<asp:BoundField DataField="ApplicationPath" HeaderText="ApplicationPath" />
<asp:BoundField DataField="ApplicationVirtualPath" HeaderText="ApplicationVirtualPath" />
<asp:BoundField DataField="MachineName" HeaderText="MachineName" />
<asp:BoundField DataField="RequestUrl" HeaderText="RequestUrl" />
<asp:BoundField DataField="ExceptionType" HeaderText="ExceptionType" />
<asp:TemplateField HeaderText="Details">
<ItemTemplate>
<asp:Label ID="Label1" runat="server">
<%= EventVariables.EventDetails %>
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowDeleteButton="True" />
</Fields>
<PagerSettings Mode="NextPreviousFirstLast" />
<PagerStyle CssClass="pager" />
</asp:DetailsView>
這是DataSource和從母體形式GirdView:
<asp:GridView
ID="ErrorGrid"
runat="server"
AutoGenerateColumns="False"
DataSourceID="SqlDataSource1"
DataKeyNames="EventId"
OnRowDeleting="ErrorGrid_RowDeleting"
AllowPaging="True"
AllowSorting="True"
Font-Size="Small"
CellPadding="10"
CellSpacing="1" >
<Columns>
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Delete" OnClientClick="return confirm('Are you sure you want to delete this record?');" Text="Delete"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:LinkButton ID="Details1" Text="Details" runat="server" AutoPostBack="true" OnClick="Details1_ButtonClick" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="EventId" HeaderText="EventId" SortExpression="EventId" />
<asp:BoundField DataField="EventTime" HeaderText="EventTime" SortExpression="EventTime" />
<asp:BoundField DataField="RequestUrl" HeaderText="RequestUrl" SortExpression="RequestUrl" />
<asp:BoundField DataField="ExceptionType" HeaderText="ExceptionType" SortExpression="ExceptionType" />
</Columns>
</asp:GridView>
<asp:SqlDataSource
ID="SqlDataSource1"
runat="server"
ConnectionString="<%$ ConnectionStrings:DefaultConnection %>"
SelectCommand="SELECT * FROM [aspnet_WebEvent_Events]"
DeleteCommand="DELETE FROM [aspnet_WebEvent_Events] WHERE [EventId][email protected]">
<DeleteParameters>
<asp:Parameter Name="EventId" />
</DeleteParameters>
</asp:SqlDataSource>
當你談論分頁爲的DetailView,這將對應於行號在GridView,對不對?或者我誤解了? – Melanie
@Melanie GridView也啓用了Paging選項。 GridView現在有7個頁面,DetailView中有72個事件和72個頁面。所以我想不出一種方法來匹配DetailView中的頁面與GridView中的頁面/行。 –