即使在调用gv.update和up.update时,删除后选项卡中的Gridview也不会更新 [英] Gridview in tab does not update after delete, even when calling gv.update and up.update
问题描述
我遇到了一个gridview,它位于一个包含更新面板的选项卡式面板上。网格显示客户过去购买的商品,它链接到表单上的clientID标签,但主键是亚麻。
我使用内置更新,一切正常,我使用内置删除(即我没有编写代码,但它被调用),但想添加删除确认并停止工作,所以我使用rowcommand进行删除,它删除数据罚款,
但是当我重新绑定网格并更新面板时它没有显示在屏幕上,如果我强制刷新页面,则gridview会显示正确的日期。
这是HTML部分代码:
< ajaxToolkit:TabContainer ID =" tabcCustomer" RUNAT = QUOT;服务器" ActiveTabIndex = QUOT 1 QUOT;的AutoPostBack = QUOT;真" >
< ajaxToolkit:TabPanel runat =" server" HeaderText =" Next Required" ID = QUOT; tabpnlNextRequired">
< HeaderTemplate>需要下一个项目< / HeaderTemplate>
< ContentTemplate>
< asp:UpdatePanel ID =" upnlNextItems" RUNAT = QUOT;服务器"的UpdateMode = QUOT;条件" ChildrenAsTriggers = QUOT;真" >
< ContentTemplate>
< div style =" padding:4px">
// ...第一个标签中的代码
< / div>
< / ContentTemplate>
<触发器>
< asp:AsyncPostBackTrigger ControlID =" btnForceNext"事件名称= QUOT;按一下[ />
< /触发器>
< / asp:UpdatePanel>
< / ContentTemplate>
< / ajaxToolkit:TabPanel>
< ajaxToolkit:TabPanel runat =" server"的HeaderText = QUOT;物品" ID = QUOT; tabpnlItems">
< HeaderTemplate>客户使用情况< / HeaderTemplate>
< ContentTemplate>
< asp:UpdateProgress ID =" updtprgItems" RUNAT = QUOT;服务器" AssociatedUpdatePanelID = QUOT; upnlItems">
< ProgressTemplate>
< img src =" ../ images / animi / BlueArrowsUpdate.gif" ALT ="更新"宽度= QUOT; 16"高度= QUOT; 16" />请等待.....< / ProgressTemplate>
< / asp:UpdateProgress>
< asp:UpdatePanel ID =" upnlItems" RUNAT = QUOT;服务器"的UpdateMode = QUOT;条件" >
< ContentTemplate>
< div class =" simpleForm" style =" padding:4px">
< div class =" simpleLightGreenForm">
< asp:GridView ID =" gvItems" RUNAT = QUOT;服务器" AllowSorting = QUOT;真" CssClass =" TblWhite small" EmptyDataText ="还没有数据"
AutoGenerateColumns =" False"的DataSourceID = QUOT; odsItemUsage" AllowPaging = QUOT;真" PagerSettings模式= QUOT; NextPreviousFirstLast"
DataKeyNames =" ClientUsageLineNo" OnRowCommand = QUOT; gvItems_RowCommand" DataKey = QUOT; ClientUsageLineNo"
PageSize =" 15" PagerSettings-FirstPageImageUrl = QUOT;〜/图片/ imgButtons / FirstPage.gif"
PagerSettings-LastPageImageUrl ="〜/ images / imgButtons / LastPage.gif"
PagerSettings-NextPageImageUrl ="〜/ images / imgButtons / NextPage.gif" PagerSettings-PreviousPageImageUrl = QUOT;〜/图片/ imgButtons / LastPage.gif" >
< Columns>
< asp:TemplateField ShowHeader =" False">
< EditItemTemplate>
< asp:ImageButton ID =" UpdateButton" RUNAT = QUOT;服务器"的CausesValidation = QUOT;真"的CommandName = [更新"
AlternateText =" Update"的ImageUrl = QUOT;〜/图片/ imgButtons / UpdateItem.gif" />
& nbsp;< asp:ImageButton ID =" CancelButton" RUNAT = QUOT;服务器"的CausesValidation = QUOT假QUOT;的CommandName = QUOT;取消]
AlternateText ="取消"的ImageUrl = QUOT;〜/图片/ imgButtons / CancelItem.gif" />
< / EditItemTemplate>
< ItemTemplate>
< asp:ImageButton ID =" EditButton" RUNAT = QUOT;服务器"的CausesValidation = QUOT假QUOT;的CommandName = QUOT;编辑"
AlternateText ="编辑"的ImageUrl = QUOT;〜/图片/ imgButtons / EditItem.gif" />&安培; NBSP;
< asp:ImageButton ID =" DeleteButton" RUNAT = QUOT;服务器"的CausesValidation = QUOT假QUOT;的CommandName = QUOT;删除"
AlternateText ="删除"的ImageUrl = QUOT;〜/图片/ imgButtons / DelItem.gif"
OnClientClick ="返回确认('您确定要删除此项吗?');"
CommandArgument ='<%#Eval(" ClientUsageLineNo")%>'/>
< / ItemTemplate>
< / asp:TemplateField>
< asp:TemplateField HeaderText =" Date"的SortExpression = QUOT;日期和QUOT;>
< EditItemTemplate>
< asp:TextBox ID =" tbxDate" RUNAT = QUOT;服务器" Text ='<%#Bind(" ItemDate"," {0:d}")%>'/>
< / EditItemTemplate>
< ItemTemplate>
< asp:Label ID =" lblData" RUNAT = QUOT;服务器" Text ='<%#Bind(" ItemDate"," {0:d}")%>'/>
< / ItemTemplate>
< / asp:TemplateField>
< asp:TemplateField HeaderText =" Item" >
< EditItemTemplate>
< asp:DropDownList ID =" ddlItems" RUNAT = QUOT;服务器"的DataSourceID = QUOT; odsItems"
DataTextField =" ItemDesc" DataValueField = QUOT; ItemTypeID" AppendDataBoundItems = QUOT;真"
SelectedValue ='<%#Bind(" ItemProvidedID")%>'>
< asp:ListItem Value =" 0"文本= QUOT; N / A" />
< / asp:DropDownList>
< / EditItemTemplate>
< ItemTemplate>
< asp:Label ID =" ItemDescLabel" RUNAT = QUOT;服务器" Text ='<%#GetItemDesc((int)Eval(" ItemProvidedID"))%>'/>
< / ItemTemplate>
< / asp:TemplateField>
< asp:BoundField DataField =" AmountProvided"的HeaderText = QUOT;数量"
SortExpression =" AmountProvided" />
< asp:TemplateField HeaderText =" Packaging"的SortExpression = QUOT; PackagingID">
< EditItemTemplate>
< asp:DropDownList ID =" ddlPackaging" RUNAT = QUOT;服务器"的DataSourceID = QUOT; odsPackagingTypes"
DataTextField =" Description" DataValueField = QUOT; PackagingID" AppendDataBoundItems = QUOT;真"
SelectedValue ='<%#Bind(" PackagingID")%>'>
< asp:ListItem Value =" 0"文本= QUOT; N / A" />
< / asp:DropDownList>
< / EditItemTemplate>
< ItemTemplate>
< asp:Label ID =" PackagingIDLabel" RUNAT = QUOT;服务器" Text ='<%#GetPackagingDesc((int)Eval(" PackagingID"))%>'>< / asp:Label>
< / ItemTemplate>
< / asp:TemplateField>
< asp:TemplateField HeaderText =" Prep Type"的SortExpression = QUOT; PrepTypeID">
< EditItemTemplate>
< asp:TextBox ID =" PrepTypeIDTextBox" RUNAT = QUOT;服务器" Text ='<%#Bind(" PrepTypeID")%>'>< / asp:TextBox>
< / EditItemTemplate>
< ItemTemplate>
< asp:Label ID =" PrepTypeIDLabel" RUNAT = QUOT;服务器" Text ='<%#Bind(" PrepTypeID")%>'>< / asp:Label>
< / ItemTemplate>
< / asp:TemplateField>
< asp:BoundField DataField =" Notes"的HeaderText = QUOT;备注"
SortExpression =" Notes" />
< asp:BoundField DataField =" CustomerID"可见= QUOT假QUOT; />
< asp:BoundField DataField =" ClientUsageLineNo"可见= QUOT假QUOT; />
< / Columns>
< PagerSettings FirstPageImageUrl ="〜/ images / imgButtons / FirstPage.gif" LastPageImageUrl = QUOT;〜/图片/ imgButtons / LastPage.gif"模式= QUOT; NumericFirstLast" NextPageImageUrl = QUOT;〜/图片/ imgButtons / NextPage.gif" PreviousPageImageUrl = QUOT;〜/图片/ imgButtons / LastPage.gif" />
< / asp:GridView>
< / div>
< / div>
< / ContentTemplate>
<触发器>
< asp:AsyncPostBackTrigger ControlID =" gvItems"事件名称= QUOT; RowCommand" />
< /触发器>
< / asp:UpdatePanel>
< / ContentTemplate>
< / ajaxToolkit:TabPanel>
< / ajaxToolkit:TabContainer>
< asp:ObjectDataSource ID =" odsItemUsage" RUNAT = QUOT;服务器"类型名= QUOT; TrackerDotNet.control.ItemUsageTbl"
SortParameterName =" SortBy"
SelectMethod =" GetAllItemsUsed"
OldValuesParameterFormatString =" original_ {0}" UpdateMethod = QUOT; UpdateItemsUsed" DeleteMethod = QUOT; DeleteItemLine" >
< DeleteParameters>
< asp:Parameter Name =" ClientUsageLineNo"类型=" Int64的" />
< / DeleteParameters>
< SelectParameters>
< asp:ControlParameter ControlID =" CompanyIDLabel"默认值= QUOT; 0"
Name =" pCustomerID"属性名= QUOT;文本"类型=" Int64的" />
< asp:参数DefaultValue ="& quot; Date& quot;"名称= QUOT; SortBy"类型="字符串" />
< / SelectParameters>
< UpdateParameters>
< asp:参数名称=" CustomerID"类型=" Int64的" />
< asp:参数名称=" ItemDate"类型=" DateTime的" />
< asp:参数名称=" ItemProvidedID"类型="&的Int32 QUOT; />
< asp:参数名称=" AmountProvided"类型="双" />
< asp:参数名称=" PrepTypeID"类型="&的Int32 QUOT; />
< asp:参数名称=" PackagingID"类型="&的Int32 QUOT; />
< asp:参数名称="注释"类型="字符串" />
< asp:Parameter Name =" original_ClientUsageLineNo"类型=" Int64的" />
< / UpdateParameters>
< / asp:ObjectDataSource>
rowcommand背后的代码,它使用keyfield直接调用objectdatasource并删除该行然后更新网格和updatepanel - 但没有任何反应,除了udpdateprogress显示一段时间,显示udpdate事件
被触发:
protected void gvItems_RowCommand(object sender,GridViewCommandEventArgs e)
{
if(e.CommandName ==" Delete")
{
ItemUsageTbl _ItemUsage = new ItemUsageTbl();
_ItemUsage.ClientUsageLineNo = Convert.ToInt64(e.CommandArgument);
_ItemUsage.DeleteItemLine(_ItemUsage.ClientUsageLineNo);
gvItems.DataBind();
upnlItems.Update();
}
}
Warren
请在ASP.NET论坛中发布ASP.NET问题:
http://forums.asp。净
I have a problem with a gridview that sits on a tabbed panel, which contains an update panel. The grid displays items a client has purchased in the past, it links to the clientID label on the form, but the primary key is the linenumber.
I use the builtin update and everything work well, I was using the built in Delete (i.e. I write no code but it gets called) but wanted to add a confirmation of delete and that stopped working, so I used rowcommand to do the delete, it deletes the data fine, but when I rebind the grid and update the panel it does not show on the screen, if I force a refresh of the page the gridview then shows the correct date.
Here is the HTML portion of the code:
<ajaxToolkit:TabContainer ID="tabcCustomer" runat="server" ActiveTabIndex="1" AutoPostBack="true" > <ajaxToolkit:TabPanel runat="server" HeaderText="Next Required" ID="tabpnlNextRequired"> <HeaderTemplate>Next Items Required</HeaderTemplate> <ContentTemplate> <asp:UpdatePanel ID="upnlNextItems" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="true" > <ContentTemplate> <div style="padding:4px"> //... code in the first tab </div> </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="btnForceNext" EventName="Click" /> </Triggers> </asp:UpdatePanel> </ContentTemplate> </ajaxToolkit:TabPanel> <ajaxToolkit:TabPanel runat="server" HeaderText="Items" ID="tabpnlItems"> <HeaderTemplate>Customer Usage</HeaderTemplate> <ContentTemplate> <asp:UpdateProgress ID="updtprgItems" runat="server" AssociatedUpdatePanelID="upnlItems"> <ProgressTemplate> <img src="../images/animi/BlueArrowsUpdate.gif" alt="updating" width="16" height="16" />please wait.....</ProgressTemplate> </asp:UpdateProgress> <asp:UpdatePanel ID="upnlItems" runat="server" UpdateMode="Conditional" > <ContentTemplate> <div class="simpleForm" style="padding: 4px"> <div class="simpleLightGreenForm"> <asp:GridView ID="gvItems" runat="server" AllowSorting="True" CssClass="TblWhite small" EmptyDataText="no data yet" AutoGenerateColumns="False" DataSourceID="odsItemUsage" AllowPaging="True" PagerSettings-Mode="NextPreviousFirstLast" DataKeyNames="ClientUsageLineNo" OnRowCommand="gvItems_RowCommand" DataKey="ClientUsageLineNo" PageSize="15" PagerSettings-FirstPageImageUrl="~/images/imgButtons/FirstPage.gif" PagerSettings-LastPageImageUrl="~/images/imgButtons/LastPage.gif" PagerSettings-NextPageImageUrl="~/images/imgButtons/NextPage.gif" PagerSettings-PreviousPageImageUrl="~/images/imgButtons/LastPage.gif" > <Columns> <asp:TemplateField ShowHeader="False"> <EditItemTemplate> <asp:ImageButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update" AlternateText="Update" ImageUrl="~/images/imgButtons/UpdateItem.gif" /> <asp:ImageButton ID="CancelButton" runat="server" CausesValidation="False" CommandName="Cancel" AlternateText="Cancel" ImageUrl="~/images/imgButtons/CancelItem.gif" /> </EditItemTemplate> <ItemTemplate> <asp:ImageButton ID="EditButton" runat="server" CausesValidation="False" CommandName="Edit" AlternateText="Edit" ImageUrl="~/images/imgButtons/EditItem.gif" /> <asp:ImageButton ID="DeleteButton" runat="server" CausesValidation="False" CommandName="Delete" AlternateText="Delete" ImageUrl="~/images/imgButtons/DelItem.gif" OnClientClick="return confirm('Are you sure you want to delete this item?');" CommandArgument='<%# Eval("ClientUsageLineNo") %>' /> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Date" SortExpression="Date"> <EditItemTemplate> <asp:TextBox ID="tbxDate" runat="server" Text='<%# Bind("ItemDate", "{0:d}") %>' /> </EditItemTemplate> <ItemTemplate> <asp:Label ID="lblData" runat="server" Text='<%# Bind("ItemDate", "{0:d}") %>' /> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Item" > <EditItemTemplate> <asp:DropDownList ID="ddlItems" runat="server" DataSourceID="odsItems" DataTextField="ItemDesc" DataValueField="ItemTypeID" AppendDataBoundItems="true" SelectedValue='<%# Bind("ItemProvidedID") %>'> <asp:ListItem Value="0" Text="n/a" /> </asp:DropDownList> </EditItemTemplate> <ItemTemplate> <asp:Label ID="ItemDescLabel" runat="server" Text='<%# GetItemDesc((int)Eval("ItemProvidedID")) %>' /> </ItemTemplate> </asp:TemplateField> <asp:BoundField DataField="AmountProvided" HeaderText="Qty" SortExpression="AmountProvided" /> <asp:TemplateField HeaderText="Packaging" SortExpression="PackagingID"> <EditItemTemplate> <asp:DropDownList ID="ddlPackaging" runat="server" DataSourceID="odsPackagingTypes" DataTextField="Description" DataValueField="PackagingID" AppendDataBoundItems="true" SelectedValue = '<%# Bind("PackagingID") %>' > <asp:ListItem Value="0" Text="n/a" /> </asp:DropDownList> </EditItemTemplate> <ItemTemplate> <asp:Label ID="PackagingIDLabel" runat="server" Text='<%# GetPackagingDesc((int)Eval("PackagingID")) %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Prep Type" SortExpression="PrepTypeID"> <EditItemTemplate> <asp:TextBox ID="PrepTypeIDTextBox" runat="server" Text='<%# Bind("PrepTypeID") %>'></asp:TextBox> </EditItemTemplate> <ItemTemplate> <asp:Label ID="PrepTypeIDLabel" runat="server" Text='<%# Bind("PrepTypeID") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:BoundField DataField="Notes" HeaderText="Notes" SortExpression="Notes" /> <asp:BoundField DataField="CustomerID" Visible="False" /> <asp:BoundField DataField="ClientUsageLineNo" Visible="False" /> </Columns> <PagerSettings FirstPageImageUrl="~/images/imgButtons/FirstPage.gif" LastPageImageUrl="~/images/imgButtons/LastPage.gif" Mode="NumericFirstLast" NextPageImageUrl="~/images/imgButtons/NextPage.gif" PreviousPageImageUrl="~/images/imgButtons/LastPage.gif" /> </asp:GridView> </div> </div> </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="gvItems" EventName="RowCommand" /> </Triggers> </asp:UpdatePanel> </ContentTemplate> </ajaxToolkit:TabPanel> </ajaxToolkit:TabContainer> <asp:ObjectDataSource ID="odsItemUsage" runat="server" TypeName="TrackerDotNet.control.ItemUsageTbl" SortParameterName="SortBy" SelectMethod="GetAllItemsUsed" OldValuesParameterFormatString="original_{0}" UpdateMethod="UpdateItemsUsed" DeleteMethod="DeleteItemLine" > <DeleteParameters> <asp:Parameter Name="ClientUsageLineNo" Type="Int64" /> </DeleteParameters> <SelectParameters> <asp:ControlParameter ControlID="CompanyIDLabel" DefaultValue="0" Name="pCustomerID" PropertyName="Text" Type="Int64" /> <asp:Parameter DefaultValue=""Date"" Name="SortBy" Type="String" /> </SelectParameters> <UpdateParameters> <asp:Parameter Name="CustomerID" Type="Int64" /> <asp:Parameter Name="ItemDate" Type="DateTime" /> <asp:Parameter Name="ItemProvidedID" Type="Int32" /> <asp:Parameter Name="AmountProvided" Type="Double" /> <asp:Parameter Name="PrepTypeID" Type="Int32" /> <asp:Parameter Name="PackagingID" Type="Int32" /> <asp:Parameter Name="Notes" Type="String" /> <asp:Parameter Name="original_ClientUsageLineNo" Type="Int64" /> </UpdateParameters> </asp:ObjectDataSource>
The the code behind for the rowcommand, it calls the objectdatasource directly using the keyfield and deletes the row then updates the grid and the updatepanel - but nothing happens, except the udpdateprogress shows for a while, showing the udpdate event is triggered :
protected void gvItems_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "Delete") { ItemUsageTbl _ItemUsage = new ItemUsageTbl(); _ItemUsage.ClientUsageLineNo = Convert.ToInt64(e.CommandArgument); _ItemUsage.DeleteItemLine(_ItemUsage.ClientUsageLineNo); gvItems.DataBind(); upnlItems.Update(); } }
Warren
Please post ASP.NET questions in the ASP.NET forums: http://forums.asp.net
这篇关于即使在调用gv.update和up.update时,删除后选项卡中的Gridview也不会更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!