编辑行时gridview排序顺序更改

时间:2013-07-11 12:49:12

标签: c# asp.net

我有一个gridview,它只是根据下拉列表中的过滤器显示记录,当我更改下拉列表页面回发正常并且过滤器工作时,但当我点击编辑一行时,排序顺序会根据新过滤器而改变。当我将下拉菜单更改回原始过滤器并单击编辑时,排序顺序保持不变。

任何想法?

<asp:DropDownList ID="ddlFilterDocs" runat="server" 
                     AutoPostBack="True" 
                     onselectedindexchanged="ddlFilterDocs_SelectedIndexChanged">
                                      <asp:ListItem Text="MissingData" 
Value="MissingData" >MissingData</asp:ListItem>
                                       <asp:ListItem Text="AllData" Value="AllData" 
>AllData</asp:ListItem>
           </asp:DropDownList>



<asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
                 AllowSorting="True" PageSize="35" 
                 AutoGenerateColumns="False" CellPadding="4" 
                 ForeColor="#333333" GridLines="None" 
                 onrowcommand="GridView1_RowCommand" DataKeyNames="customerCode" 
                 onpageindexchanging="GridView1_PageIndexChanging" 
                 onsorting="GridView1_Sorting">
                 <AlternatingRowStyle BackColor="White" />
                 <Columns>
                       <asp:TemplateField SortExpression="CustomerCode">
                         <ItemTemplate>
                            <asp:LinkButton ID="lbEdit" ForeColor="DarkGreen" Font-   
Bold="True" CommandArgument='<%# Eval("customerCode") %>' CommandName="EditRow" 
runat="server">Edit</asp:LinkButton>
                           </ItemTemplate>
                         <EditItemTemplate>
                                     <asp:LinkButton ID="lbUpdate" CommandArgument='<%# 
Eval("customerCode") %>' CommandName="UpdateRow" runat="server"  
ForeColor="White">Update</asp:LinkButton>
                             <asp:LinkButton ID="lblCancel" CommandArgument='<%# 
Eval("customerCode") %>' CommandName="CancelUpdate" runat="server"  
ForeColor="White">Cancel</asp:LinkButton>
                          </EditItemTemplate>
                           <HeaderStyle Width="100px" />
                     </asp:TemplateField>

                     <asp:TemplateField  HeaderText="Customer ID" 
SortExpression="CustomerCode">
                         <EditItemTemplate>
                             <asp:Label ID="lblCustCodeEdit" runat="server" Text='<%# 
Eval("CustomerCode") %>'></asp:Label>
                         </EditItemTemplate>
                         <ItemTemplate>
                             <asp:Label ID="lblCustCode" runat="server" Text='<%# 
Bind("CustomerCode") %>'></asp:Label>
                         </ItemTemplate>
                     </asp:TemplateField>
                     <asp:BoundField  DataField="Name" HeaderText="Name" 
SortExpression="Name" 
                           ReadOnly="True" >
                       <HeaderStyle Width="100px" />
                       </asp:BoundField>
                     <asp:TemplateField HeaderText="StreetAddress" 
SortExpression="StreetAddress">
                         <EditItemTemplate>
                             <asp:TextBox ID="tbxStreetAddress" runat="server" 
Text='<%# Bind("StreetAddress") %>'></asp:TextBox>
                         </EditItemTemplate>
                         <ItemTemplate>
                             <asp:Label ID="lblStreetAddress" runat="server" Text='<%# 
Bind("StreetAddress") %>'></asp:Label>
                         </ItemTemplate>
                         <HeaderStyle Width="150px" />
                     </asp:TemplateField>
                     <asp:TemplateField HeaderText="City" SortExpression="City">
                         <EditItemTemplate>
                             <asp:TextBox ID="tbxCity" runat="server" Text='<%# 
Bind("City") %>'></asp:TextBox>
                         </EditItemTemplate>
                         <ItemTemplate>
                             <asp:Label ID="lblCity" runat="server" Text='<%# 
Bind("City") %>'></asp:Label>
                         </ItemTemplate>
                         <HeaderStyle Width="100px" />
                     </asp:TemplateField>
                     <asp:TemplateField HeaderText="Zip" SortExpression="Zip">
                         <EditItemTemplate>
                             <asp:TextBox ID="tbxZip" runat="server" Text='<%# 
Bind("Zip") %>'></asp:TextBox>
                         </EditItemTemplate>
                         <ItemTemplate>
                             <asp:Label ID="lblZip" runat="server" Text='<%# 
Bind("Zip") %>'></asp:Label>
                         </ItemTemplate>
                         <HeaderStyle Width="50px" />
                     </asp:TemplateField>
                     <asp:BoundField DataField="DocNumber" HeaderText="DocNumber" 
                         SortExpression="DocNumber" ReadOnly="True">
                       <HeaderStyle Width="50px" />
                       </asp:BoundField>
                     <asp:BoundField DataField="GrossAmount" HeaderText="Gross" 
                         SortExpression="GrossAmount"  ReadOnly="True" 
DataFormatString="{0:c2}"  >
                       <HeaderStyle Width="70px" />
                       </asp:BoundField>
                     <asp:BoundField DataField="NetAmount" HeaderText="Net" 
                         SortExpression="NetAmount"  ReadOnly="True" DataFormatString="
{0:c2}" >
                       <HeaderStyle Width="70px" />
                       </asp:BoundField>
                     <asp:BoundField DataField="VATAmount" HeaderText="VAT" 
                         SortExpression="VATAmount"  ReadOnly="True" DataFormatString="
{0:c2}" >
                       <HeaderStyle Width="70px" />
                       </asp:BoundField>
                     <asp:BoundField DataField="FromVoucNbr" HeaderText="Voucher" 
                         SortExpression="FromVoucNbr"  ReadOnly="True" >
                       <HeaderStyle Width="70px" />
                       </asp:BoundField>
                     <asp:BoundField DataField="LastModDate" HeaderText="Date" 
                         SortExpression="LastModDate"  ReadOnly="True" 
DataFormatString="{0:G}" >
                       <HeaderStyle Width="70px" />
                       </asp:BoundField>
                     <asp:BoundField DataField="LastModUser" HeaderText="LastModUser" 
                         SortExpression="LastModUser"   ReadOnly="True">
                       <HeaderStyle Width="50px" />
                       </asp:BoundField>
                 </Columns>
                 <EditRowStyle BackColor="#7C6F57" />
                 <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
                 <HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
                 <PagerStyle BackColor="#666666" ForeColor="White" 
HorizontalAlign="Center" />
                 <RowStyle BackColor="#E3EAEB" />
                 <SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" 
ForeColor="#333333" />
                 <SortedAscendingCellStyle BackColor="#F8FAFA" />
                 <SortedAscendingHeaderStyle BackColor="#246B61" />
                 <SortedDescendingCellStyle BackColor="#D4DFE1" />
                 <SortedDescendingHeaderStyle BackColor="#15524A" />
             </asp:GridView>

1 个答案:

答案 0 :(得分:0)

如果要将数据重新绑定到Row_Editing事件中,则需要使用下拉选择值对其进行过滤。

此致