asp.net更新面板问题 [英] asp.net update panel issue
本文介绍了asp.net更新面板问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用asp.net。我的gridview有一个select2脚本的下拉列表。当我按gridview中的添加按钮时,我的select2脚本无效。这在添加更新面板后发生。请帮助
这里代码:
I'm using asp.net. my gridview have a dropdown with select2 script.when i press add button in gridview my select2 script not working. this happens after add update panel. Please help
Here code :
<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Always">
<ContentTemplate>
<asp:GridView ID="grdItems" runat="server" AutoGenerateColumns="False" Font-Names="Arial" ClientIDMode="Static" CssClass="table table-striped table-bordered table-hover" Width="100%" Font-Size="11pt" AlternatingRowStyle-BackColor="#C2D69B" HeaderStyle-BackColor="green" AllowPaging="False" ShowFooter="False" OnRowCommand="grdItems_RowCommand" DataKeyNames="RowId,ItemId">
<Columns>
<asp:TemplateField HeaderText="No">
<ItemTemplate>
<asp:DropDownList ID="ddlNo" Font-Size="12px" runat="server" CssClass="js-example-placeholder-single" Width="100%" AutoPostBack="true" TabIndex="1" OnSelectedIndexChanged="ddlNo_SelectedIndexChanged"></asp:DropDownList>
</ItemTemplate>
<HeaderStyle Font-Bold="true" Font-Names="Tahoma" Font-Size="12px" Width="15%" BackColor="#8DC894"
ForeColor="Green" HorizontalAlign="Left" />
<ItemStyle HorizontalAlign="Left" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Qty(Pcs)">
<ItemTemplate>
<asp:TextBox ID="txtQty" runat="server" AutoCompleteType="None" Text='<%# Bind("Qty") %>'
ClientIDMode="Static" CssClass="form-control text-right" onkeyup="Calculate();"
onkeypress="return isNumberKey(event)" TabIndex="2"></asp:TextBox>
</ItemTemplate>
<HeaderStyle Font-Bold="true" Font-Names="Tahoma" CssClass="text-right" Font-Size="12px" Width="5%" BackColor="#8DC894" ForeColor="Green" HorizontalAlign="Right" />
<ItemStyle HorizontalAlign="Right" />
<FooterTemplate>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="btnAddNewRow" ToolTip="Add New Contract" CommandArgument="RowId"
CommandName="Add" CssClass="GridAddbtn" runat="server" TabIndex="3" />
<asp:Button ID="btngridDelete" ToolTip="Delete" CommandArgument="RowId" CommandName="Delete" data-target="#mpSearch"
CssClass="GridDeletebtn" runat="server" TabIndex="4" />
</ItemTemplate>
<HeaderStyle Font-Bold="true" Font-Names="Tahoma" Font-Size="12px" Width="5%" BackColor="#8DC894" ForeColor="Green" HorizontalAlign="Left" />
<ItemStyle HorizontalAlign="Right" />
</asp:TemplateField>
</Columns>
<AlternatingRowStyle BackColor="#C2D69B" />
<HeaderStyle BackColor="Green"></HeaderStyle>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
这是javascript代码:
this is javascript code :
<script type="text/javascript">
$(".js-example-placeholder-single").select2({
placeholder: "Select a state",
allowClear: true
});
</script>
推荐答案
( .js-example-placeholder-single)。select2({
占位符: 选择状态,
allowClear: true
});
< / script>
(".js-example-placeholder-single").select2({ placeholder: "Select a state", allowClear: true }); </script>
尝试将脚本移动到名为pageLoad
的全局函数:
Try moving the script to a global function calledpageLoad
:
<script>
function pageLoad(){
( 。js-example-placeholder-single)。select2({
placeholder: 选择状态,
allowClear: true
});
}
< / 脚本 >
(".js-example-placeholder-single").select2({ placeholder: "Select a state", allowClear: true }); } </script>
如果每页只需要一个启动脚本,那将会有效。如果您需要多个,请尝试:
That will work if you only need a single startup script per page. If you need more than one, then try:
<script>
这篇关于asp.net更新面板问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文