最佳解答者
PostBack後, GridView的Pager 重設了.

問題
-
<table style="width: 970px" cellpadding="0" cellspacing="0" border="0"> <tr> <td style='width: 100px'> </td> <td> <asp:TextBox ID="txtSearchTitle" runat="server" Height="20px" Width="280px" CssClass="field_search_input"></asp:TextBox> </td> <td rowspan="2" align="center"> <asp:UpdatePanel ID="UpdatePanel_Input" runat="server" UpdateMode="Conditional"> <Triggers> <asp:AsyncPostBackTrigger ControlID="btnSearch" /> <asp:PostBackTrigger ControlID="btnReset" /> </Triggers> <ContentTemplate> <asp:Button ID="btnSearch" runat="server" CssClass="button1" Text="Search" Width="88px" /> <asp:Button ID="btnReset" runat="server" CssClass="button1" Font-Size="10pt" Text="Reset" Width="88px" CausesValidation="false" /> </ContentTemplate> </asp:UpdatePanel> </td> </tr> </table> <asp:UpdatePanel ID="UpdatePanel_GridView" runat="server" UpdateMode="Conditional"> <Triggers> <asp:AsyncPostBackTrigger ControlID="btnSearch" /> </Triggers> <ContentTemplate> <asp:GridView ID="gdvList" runat="server" AllowPaging="True" AutoGenerateColumns="False" OnPageIndexChanging="PageIndexChanging" ForeColor="Black" CssClass="datatable" CellPadding="0" BorderWidth="0px" GridLines="None" Width="950px" Font-Size="10pt" PageSize="5" AllowSorting="False" PagerSettings-Mode="Numeric" PagerSettings-Position="Bottom"> <Columns> <asp:TemplateField ItemStyle-Width="80px" ItemStyle-HorizontalAlign="Center" HeaderText="Name" Visible="false"> <ItemTemplate> <asp:Label ID="lblLawNo" runat="server"><%#Eval("Name")%></asp:Label> </ItemTemplate> <ItemStyle HorizontalAlign="Center" Width="60px"></ItemStyle> </asp:TemplateField> <asp:TemplateField HeaderText="Document"> <HeaderTemplate> </HeaderTemplate> <ItemTemplate> <asp:ImageButton ID="btnDocLink" runat="server" ImageUrl="~/Images/doc.gif" /> <cc1:ModalPopupExtender ID="ModalPopupExtender_DocLink" runat="server" PopupControlID="DocPanel" BackgroundCssClass="modalBackground" TargetControlID="btnDocLink" CancelControlID="btnClose"> </cc1:ModalPopupExtender> </ItemTemplate> <HeaderStyle /> <ItemStyle HorizontalAlign="Center" Width="20px"></ItemStyle> </asp:TemplateField> </Columns> </asp:GridView> </ContentTemplate> </asp:UpdatePanel> <asp:Panel ID="panelUpdateProgress" runat="server" CssClass="updateProgress"> <asp:UpdateProgress ID="UpdateProg1" DisplayAfter="0" runat="server" AssociatedUpdatePanelID="UpdatePanel_Input"> <ProgressTemplate> <div style="position: relative; top: 30%; text-align: center;"> <img src="Images/animated_loading.gif" style="vertical-align: middle" alt="Processing" /> Processing ... </div> </ProgressTemplate> </asp:UpdateProgress> </asp:Panel> <cc1:ModalPopupExtender ID="ModalProgress" runat="server" TargetControlID="panelUpdateProgress" BackgroundCssClass="modalBackground" PopupControlID="panelUpdateProgress" /> <asp:Panel ID="DocPanel" runat="server" Style="display: none;" Width="900px" Height="650" > <div class="footer" style="text-align:left"> </div> <div class="footer" style="text-align:right"> <asp:ImageButton ID="btnClose" runat="server" AlternateText="Close" ImageUrl="~/Images/CloseX.png" CausesValidation="false" Width="38px" Height="38px" OnClientClick="download('')"/> </div> <asp:Button ID="btnShowPopup" runat="server" Style="display: none" /> <iframe id="DocFrame" Width="900px" Height="600"></iframe> </asp:Panel> --------- Protected Sub btnReset_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnReset.Click Me.txtSearchTitle.Text = String.Empty End Sub Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearch.Click ds = da.GetList(txtSearch.text) Me.gdvList.DataSource = ds.Tables(0).DataSet Me.gdvList.DataBind() End Sub Protected Sub gdvList_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gdvList.RowDataBound If e.Row.RowType = DataControlRowType.Pager Then Dim pagerCell As TableCell pagerCell = CType(e.Row.Controls(0), TableCell) Dim txt As String Dim txtGoPage As String txtGoPage = "Page No:" txt = "<span><font size='2pt'>" & txtGoPage & " </font><span class=i>" pagerCell.Controls.AddAt(0, New LiteralControl(txt)) pagerCell.Controls.AddAt(pagerCell.Controls.Count, New LiteralControl("</span></span>")) End If End SUb 現在 btnReset 放UpdatePanel 外面, 按下btnReset後, GridView的Pager ( Page NO: ) 消失了.
要再按 btnSearch 一次就再出現,
如果 btnReset 放UpdatePanel 內面, 按下btnReset後, GridView的Pager ( Page NO: ) 沒有問題
但 txtSearchTitle 的內容就不能設為空白.2009年3月26日 上午 06:39
解答
-
Lam0706 你好
你可不可以 將你的 update panel (UpdatePanel_Input)
把他 surround 你的 第一個table
這樣你便不用 將 reset button 放到 update panel 外面了
pager 亦都應該 不會消失
e.g.
<asp:UpdatePanel ID="UpdatePanel_Input" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnSearch" />
<asp:PostBackTrigger ControlID="btnReset" />
</Triggers>
<ContentTemplate>
<table style="width: 970px" cellpadding="0" cellspacing="0" border="0">
<tr>
<td style='width: 100px'>
</td>
<td>
<asp:TextBox ID="txtSearchTitle" runat="server" Height="20px" Width="280px" CssClass="field_search_input"></asp:TextBox>
</td>
<td rowspan="2" align="center">
<asp:Button ID="btnSearch" runat="server" CssClass="button1" Text="Search" Width="88px" />
<asp:Button ID="btnReset" runat="server" CssClass="button1" Font-Size="10pt" Text="Reset"
Width="88px" CausesValidation="false" OnClick="btnReset_Click" />
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
我 bold 了我改了的code.
Hope this can help.
Chi- 已標示為解答 Lam0706 2009年3月30日 上午 09:44
2009年3月26日 上午 08:32
所有回覆
-
Lam0706 你好
你可不可以 將你的 update panel (UpdatePanel_Input)
把他 surround 你的 第一個table
這樣你便不用 將 reset button 放到 update panel 外面了
pager 亦都應該 不會消失
e.g.
<asp:UpdatePanel ID="UpdatePanel_Input" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnSearch" />
<asp:PostBackTrigger ControlID="btnReset" />
</Triggers>
<ContentTemplate>
<table style="width: 970px" cellpadding="0" cellspacing="0" border="0">
<tr>
<td style='width: 100px'>
</td>
<td>
<asp:TextBox ID="txtSearchTitle" runat="server" Height="20px" Width="280px" CssClass="field_search_input"></asp:TextBox>
</td>
<td rowspan="2" align="center">
<asp:Button ID="btnSearch" runat="server" CssClass="button1" Text="Search" Width="88px" />
<asp:Button ID="btnReset" runat="server" CssClass="button1" Font-Size="10pt" Text="Reset"
Width="88px" CausesValidation="false" OnClick="btnReset_Click" />
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
我 bold 了我改了的code.
Hope this can help.
Chi- 已標示為解答 Lam0706 2009年3月30日 上午 09:44
2009年3月26日 上午 08:32