ASP.NET UpdatePanel 中的 GridView 直到第二次点击才会更新
ASP.NET GridView inside UpdatePanel doesn't update until second click
我在网上寻找答案,但没有找到任何答案。我在 UpdatePanel 和一个 Linkbutton 列中有一个 GridView,用于在 Bootstrap 模式中显示一些细节。我有一个问题,当用户点击 LinkButton 时,事件 OnClick 没有触发,所以,为了解决这个问题,我在 Javascript 中做了一个函数,它只会导致点击另一个 LinkButton 来触发 OnClick 事件。
现在它工作正常,但在第二次单击之前没有任何变化。
ASP.NET代码
<asp:UpdatePanel ID="upContent" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<table align="center">
<tr>
<td>
<asp:GridView ID="grvOrderTracing" runat="server" EmptyDataText="There are no pending orders for the selected date" AutoGenerateColumns="False" DataSourceID="SqlDTSgetOrdersByDate" CssClass="table table-striped table-hover table-responsive" GridLines="None" AllowPaging="True" PageSize="8" >
<PagerStyle CssClass="pagination-ys" />
<Columns>
<asp:BoundField DataField="Order ID" HeaderText="Order ID" SortExpression="Order ID" >
<ControlStyle CssClass="hide" />
<FooterStyle CssClass="hide" />
<HeaderStyle CssClass="hide" />
<ItemStyle CssClass="hide" />
</asp:BoundField>
<asp:TemplateField HeaderText="Order Number">
<ItemTemplate>
<asp:LinkButton ID="lbtShowMoreInfo" runat="server" data-toggle="modal" data-target="#showLog" CommandName="OrderID" Text='<%# Bind("[Order Number]") %>' style="cursor: pointer; font-weight: bold;" OnClientClick="ActivityLog(this);">
</asp:LinkButton>
<asp:LinkButton ID="lbtActivityLog" runat="server" CommandName="OrderID" CssClass="hide" OnClick="ActivityLog_Click" Text='<%# Bind("[Order ID]") %>' ></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDTSgetOrdersByDate" runat="server" ConnectionString="<%$ ConnectionStrings:DefaultConnection %>" SelectCommand="sp_getOrdersByDate" SelectCommandType="StoredProcedure" CancelSelectOnNullParameter="False">
<SelectParameters>
<asp:Parameter DefaultValue="0" Name="filter" Type="Int32" />
<asp:Parameter Name="startDate" Type="String" />
<asp:Parameter Name="endDate" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel ID="upLog" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<!-- Modal -->
<div id="showLog" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" data-backdrop="static" data-keyboard="false">
<div class="modal-dialog modal-lg" >
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Orden Log</h4>
</div>
<div class="modal-body">
<asp:GridView ID="grvLog" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDTSgetTracing" CssClass="table table-striped table-hover table-responsive" GridLines="None" >
<Columns>
<asp:BoundField DataField="Movement Date" HeaderText="Movement Date" SortExpression="Movement Date" ReadOnly="true" DataFormatString="{0:dd/MM/yyyy HH:mm}" />
<asp:BoundField DataField="User" HeaderText="User" SortExpression="User" ReadOnly="true" />
<asp:BoundField DataField="Action" HeaderText="Action" SortExpression="Action" ReadOnly="true" />
<asp:BoundField DataField="Comments" HeaderText="Comments" SortExpression="Comments"/>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDTSgetTracing" runat="server" ConnectionString="<%$ ConnectionStrings:DefaultConnection %>" SelectCommand="sp_getTracing" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:Parameter DefaultValue="0" Name="ord_id" Type="Int32"/>
</SelectParameters>
</asp:SqlDataSource>
</div>
</div>
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
Javascript代码
function ActivityLog(lbt) {
lbt.nextSibling.nextSibling.click(); //Find the other LinkButton and click
}
C#代码
protected void ActivityLog_Click(object sender, EventArgs e)
{
SqlDTSgetTracing.SelectParameters["ord_id"].DefaultValue = ((LinkButton)sender).Text;
SqlDTSgetTracing.Select(DataSourceSelectArguments.Empty);
grvLog.DataBind();
upLog.Update();
}
When clicnking the seccond time
点击两次后,数据显示在 GridView 中。
我希望从第一次单击开始就在 GridView 中显示数据。
我认为您可能希望将 return false;
附加到 OnClientClick
的末尾,以防止该控件的其余单击事件(由 ASP.NET 为您编码)来自 运行.这将确保只有您关心的 LinkButton
会回发。
OnClientClick="ActivityLog(this);return false;"
不确定这是否会解决点击两次的问题,但也许吧!
我在网上寻找答案,但没有找到任何答案。我在 UpdatePanel 和一个 Linkbutton 列中有一个 GridView,用于在 Bootstrap 模式中显示一些细节。我有一个问题,当用户点击 LinkButton 时,事件 OnClick 没有触发,所以,为了解决这个问题,我在 Javascript 中做了一个函数,它只会导致点击另一个 LinkButton 来触发 OnClick 事件。
现在它工作正常,但在第二次单击之前没有任何变化。
ASP.NET代码
<asp:UpdatePanel ID="upContent" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<table align="center">
<tr>
<td>
<asp:GridView ID="grvOrderTracing" runat="server" EmptyDataText="There are no pending orders for the selected date" AutoGenerateColumns="False" DataSourceID="SqlDTSgetOrdersByDate" CssClass="table table-striped table-hover table-responsive" GridLines="None" AllowPaging="True" PageSize="8" >
<PagerStyle CssClass="pagination-ys" />
<Columns>
<asp:BoundField DataField="Order ID" HeaderText="Order ID" SortExpression="Order ID" >
<ControlStyle CssClass="hide" />
<FooterStyle CssClass="hide" />
<HeaderStyle CssClass="hide" />
<ItemStyle CssClass="hide" />
</asp:BoundField>
<asp:TemplateField HeaderText="Order Number">
<ItemTemplate>
<asp:LinkButton ID="lbtShowMoreInfo" runat="server" data-toggle="modal" data-target="#showLog" CommandName="OrderID" Text='<%# Bind("[Order Number]") %>' style="cursor: pointer; font-weight: bold;" OnClientClick="ActivityLog(this);">
</asp:LinkButton>
<asp:LinkButton ID="lbtActivityLog" runat="server" CommandName="OrderID" CssClass="hide" OnClick="ActivityLog_Click" Text='<%# Bind("[Order ID]") %>' ></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDTSgetOrdersByDate" runat="server" ConnectionString="<%$ ConnectionStrings:DefaultConnection %>" SelectCommand="sp_getOrdersByDate" SelectCommandType="StoredProcedure" CancelSelectOnNullParameter="False">
<SelectParameters>
<asp:Parameter DefaultValue="0" Name="filter" Type="Int32" />
<asp:Parameter Name="startDate" Type="String" />
<asp:Parameter Name="endDate" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel ID="upLog" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<!-- Modal -->
<div id="showLog" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" data-backdrop="static" data-keyboard="false">
<div class="modal-dialog modal-lg" >
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Orden Log</h4>
</div>
<div class="modal-body">
<asp:GridView ID="grvLog" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDTSgetTracing" CssClass="table table-striped table-hover table-responsive" GridLines="None" >
<Columns>
<asp:BoundField DataField="Movement Date" HeaderText="Movement Date" SortExpression="Movement Date" ReadOnly="true" DataFormatString="{0:dd/MM/yyyy HH:mm}" />
<asp:BoundField DataField="User" HeaderText="User" SortExpression="User" ReadOnly="true" />
<asp:BoundField DataField="Action" HeaderText="Action" SortExpression="Action" ReadOnly="true" />
<asp:BoundField DataField="Comments" HeaderText="Comments" SortExpression="Comments"/>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDTSgetTracing" runat="server" ConnectionString="<%$ ConnectionStrings:DefaultConnection %>" SelectCommand="sp_getTracing" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:Parameter DefaultValue="0" Name="ord_id" Type="Int32"/>
</SelectParameters>
</asp:SqlDataSource>
</div>
</div>
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
Javascript代码
function ActivityLog(lbt) {
lbt.nextSibling.nextSibling.click(); //Find the other LinkButton and click
}
C#代码
protected void ActivityLog_Click(object sender, EventArgs e)
{
SqlDTSgetTracing.SelectParameters["ord_id"].DefaultValue = ((LinkButton)sender).Text;
SqlDTSgetTracing.Select(DataSourceSelectArguments.Empty);
grvLog.DataBind();
upLog.Update();
}
When clicnking the seccond time
点击两次后,数据显示在 GridView 中。
我希望从第一次单击开始就在 GridView 中显示数据。
我认为您可能希望将 return false;
附加到 OnClientClick
的末尾,以防止该控件的其余单击事件(由 ASP.NET 为您编码)来自 运行.这将确保只有您关心的 LinkButton
会回发。
OnClientClick="ActivityLog(this);return false;"
不确定这是否会解决点击两次的问题,但也许吧!