如何美元selectedindexchange为DropDownList的p $ pvent整页回发 [英] How to prevent full page postback on selectedindexchange for dropdownlist
问题描述
< ASP:的UpdatePanel =服务器的ClientIDMode =静态ID =TasksUpdatePanel的UpdateMode =条件>
<&的ContentTemplate GT;
< ASP:面板ID =pnlDropDown=服务器的ClientIDMode =静态的CssClass =pnlDropDown>
<! - 任务名称 - >
< ASP:DropDownList的ID =ddlTaskName的CssClass =选择选的DataSourceID =dsPopulateTaskName的AutoPostBack =真DataValueField =任务名称=服务器WIDTH =100%FONT-SIZE =11像素AppendDataBoundItems =真OnSelectedIndexChanged =ddlTaskName_onSelectIndexChanged>
< ASP:ListItem的文本=所有VALUE =%>< / ASP:ListItem的>
< / ASP:DropDownList的> < / ASP:面板>
< ASP:GridView的ShowHeaderWhenEmpty =false的AlternatingRowStyle-背景色=#EBE9E9的AutoGenerateColumns =false的OnSorting =yourTasksGV_SortingAllowSorting =真正的ID =yourTasksGV=服务器的ClientIDMode =静态EmptyDataText = 你现在有没有任务分配给你OnRowDataBound =yourTasksGV_RowDataBoundOnRowCreated =yourTasksGV_RowCreated>
<柱体和GT;
< ASP:的TemplateField HeaderStyle宽度=2%>
<&ItemTemplate中GT;
< ASP:ImageButton的的ImageUrl =〜/ cies.png=服务器ID =btnShowDepend按需=btnShowDepend_Command的CommandName =TaskDependCommandArgument ='<%#的eval(的TestIt)%> 工具提示=点击查看相关性/>
< / ItemTemplate中>
< / ASP:的TemplateField>
< ASP:HyperLinkField字段HeaderStyle-WIDTH =16%目标=_自我DataNavigateUrlFields =任务详细信息DataTextField =任务名称DataNavigateUrlFormatString =的HeaderText =任务详细信息SORTEX pression =任务名称 ItemStyle-的CssClass =taskTableColumn/>
< ASP:BoundField的HeaderStyle-WIDTH =10%的数据字段=工作组的HeaderText =工作组SORTEX pression =工作组ItemStyle-的CssClass =taskTableColumn/>
< ASP:BoundField的HeaderStyle宽度=7%数据字段=状态的HeaderText =状态SORTEX pression =状态ItemStyle-的CssClass =taskTableColumn/>
< /专栏>
< / ASP:GridView的>
< /&的ContentTemplate GT;
<% - <&触发器GT;
< ASP:AsyncPostBackTrigger控件ID =ddlTaskName事件名称=onSelectIndexChanged/>
< /触发器> - %GT;
< / ASP:的UpdatePanel>
每当执行 ddlTaskName_onSelectIndexChanged
函数有一个完整的网页回发,而不仅仅是更新的UpdatePanel
ddlTaskName_onSelectIndexChanged
功能:
保护无效ddlTaskName_onSelectIndexChanged(对象发件人,EventArgs的发送)
{
PullData(的ViewState [sortExp]的ToString()的ViewState [中将sortOrder]的ToString()为false。); //调用一个函数来更新GridView控件
}
通过上面的code,页面做一个完整的回发,而不仅仅是部分(只更新GridView的),只要该指数是在改变了 ddlTaskName
我可以添加/什么code修改,以确保不执行完全回发,只更新GridView的索引改变。
以为......我是否需要添加它们在两个单独的UpdatePanel?
如果我取消注释触发
,我收到以下错误: ID为ddlTaskName控制找不到在UpdatePanel的触发器TasksUpdatePanel。
我附上的DropDownList到GridView是这样的:
是不是因为这样的:
保护无效yourTasksGV_RowCreated(对象发件人,GridViewRowEventArgs E)
{
如果(e.Row.RowType == DataControlRowType.Header)
{
GridView控件hGrid =(GridView的)发件人;
GridViewRow gvrRow =新GridViewRow(0,0,DataControlRowType.Header,DataControlRowState.Insert); TableHeaderCell tcCellTask =新TableHeaderCell();
tcCellTask.Controls.Add(ddlTaskName);
gvrRow.Cells.Add(tcCellTask); yourTasksGV.Controls [0] .Controls.AddAt(0,gvrRow);
}
}
您code似乎罚款。你尝试注释掉的asp:面板标签?
如果你unccoment触发器,你需要把ASP:GridView的周围的UpdatePanel
<asp:UpdatePanel runat="server" ClientIDMode="Static" ID="TasksUpdatePanel" UpdateMode="Conditional">
<ContentTemplate>
<asp:Panel ID="pnlDropDown" runat="server" ClientIDMode="Static" CssClass="pnlDropDown">
<!-- TASK NAME -->
<asp:DropDownList ID="ddlTaskName" CssClass="chosen-select" DataSourceID="dsPopulateTaskName" AutoPostBack="true" DataValueField="Task Name" runat="server" Width="100%" Font-Size="11px" AppendDataBoundItems="true" OnSelectedIndexChanged="ddlTaskName_onSelectIndexChanged">
<asp:ListItem Text="All" Value="%"></asp:ListItem>
</asp:DropDownList>
</asp:Panel>
<asp:GridView ShowHeaderWhenEmpty="false" AlternatingRowStyle-BackColor="#EBE9E9" AutoGenerateColumns="false" OnSorting="yourTasksGV_Sorting" AllowSorting="true" ID="yourTasksGV" runat="server" ClientIDMode="Static" EmptyDataText="You currently have no tasks assigned to you" OnRowDataBound="yourTasksGV_RowDataBound" OnRowCreated="yourTasksGV_RowCreated">
<Columns>
<asp:TemplateField HeaderStyle-Width="2%">
<ItemTemplate>
<asp:ImageButton ImageUrl="~/cies.png" runat="server" ID="btnShowDepend" OnCommand="btnShowDepend_Command" CommandName="TaskDepend" CommandArgument='<%#Eval("TestIt") %>' ToolTip="Click to view Dependencies" />
</ItemTemplate>
</asp:TemplateField>
<asp:HyperLinkField HeaderStyle-Width="16%" Target="_self" DataNavigateUrlFields="Task Detail" DataTextField="Task Name" DataNavigateUrlFormatString="" HeaderText="Task Detail" SortExpression="Task Name" ItemStyle-CssClass="taskTableColumn" />
<asp:BoundField HeaderStyle-Width="10%" DataField="Workgroup" HeaderText="Workgroup" SortExpression="Workgroup" ItemStyle-CssClass="taskTableColumn" />
<asp:BoundField HeaderStyle-Width="7%" DataField="Status" HeaderText="Status" SortExpression="Status" ItemStyle-CssClass="taskTableColumn" />
</Columns>
</asp:GridView>
</ContentTemplate>
<%--<Triggers>
<asp:AsyncPostBackTrigger ControlID="ddlTaskName" EventName="onSelectIndexChanged" />
</Triggers>--%>
</asp:UpdatePanel>
Whenever the ddlTaskName_onSelectIndexChanged
function is executed there is a full page postback rather than just updating the UpdatePanel
ddlTaskName_onSelectIndexChanged
function:
protected void ddlTaskName_onSelectIndexChanged(object sender, EventArgs e)
{
PullData(ViewState["sortExp"].ToString(), ViewState["sortOrder"].ToString(), false); //calls a function to update the GridView
}
With the above code, the page does a full postback rather than just partial (only update the GridView) whenever the index is changed in the ddlTaskName
What code can I add/modify to ensure the full postback isn't executed and only update the GridView on index changed.
Thought... Do I need to add them in two separate UpdatePanel?
If I uncomment the triggers
, I get the following error: A control with ID 'ddlTaskName' could not be found for the trigger in UpdatePanel 'TasksUpdatePanel'.
I am attaching the dropdownlist to the Gridview like this:
Is it because of this:
protected void yourTasksGV_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
GridView hGrid = (GridView)sender;
GridViewRow gvrRow = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Insert);
TableHeaderCell tcCellTask = new TableHeaderCell();
tcCellTask.Controls.Add(ddlTaskName);
gvrRow.Cells.Add(tcCellTask);
yourTasksGV.Controls[0].Controls.AddAt(0, gvrRow);
}
}
your code seems fine. did you try to comment out asp:Panel tab? if you unccoment triggers, you need to put asp:UpdatePanel around gridview
这篇关于如何美元selectedindexchange为DropDownList的p $ pvent整页回发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!