2013-01-25 88 views
2

我正在使用SortExpression="fieldName"排序我的GridView的列。 而且工作完美!但是現在,當我點擊「列標題」時,它會重定向到另一個頁面......並且無論哪一列我嘗試排序,它總是會重定向到同一頁面。我不知道它會是什麼。任何線索?
這裏是我的GridView:排序重定向到另一頁

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" style="font-family: Verdana, Arial, Sans-Serif" 
      DataKeyNames="id" 
      CssClass="gridview" DataSourceID="MyDataSource" 
      AllowSorting ="True" AllowPaging="True" BackColor="#CCCCCC" 
      BorderStyle="Inset" BorderWidth="2px" BorderColor="GrayText" 
      CellPadding="1" 
      CellSpacing="5" 
      HeaderStyle-HorizontalAlign="Center" 
      OnRowDataBound="GridView1_RowDataBound" 
      ForeColor = "Black" RowStyle-CssClass="gridview" 
      onrowcommand="GridView1_RowCommand">    
      <AlternatingRowStyle BackColor="#CCCCCC" /> 
       <columns> 

        <asp:BoundField HeaderText="ID" DataField="id" /> 
        <asp:BoundField HeaderText="PRIORIDADE" DataField="prioridade" ItemStyle-HorizontalAlign="Center" /> 
        <asp:BoundField HeaderText="SITUAÇÃO" DataField="situacao" ItemStyle-HorizontalAlign="Center" > 
        <ItemStyle HorizontalAlign="Center" /> 
        </asp:BoundField> 
        <asp:BoundField HeaderText="RESPONSAVEL" DataField="responsavel" HeaderStyle-Width="65px" ItemStyle-HorizontalAlign="Center"> 
        <HeaderStyle Width="65px" /> 
        <ItemStyle HorizontalAlign="Center" /> 
        </asp:BoundField> 
        <asp:BoundField HeaderText="DATA DE CADASTRO" DataField="dt_cadastro" SortExpression="dt_cadastro" DataFormatString="{0:dd/MM/yyyy}" HeaderStyle-Width="60px" 
        ItemStyle-HorizontalAlign="Center" > 
        <HeaderStyle Width="60px" /> 
        <ItemStyle HorizontalAlign="Center" /> 
        </asp:BoundField> 
        <asp:BoundField HeaderText="PREVISÃO DE TÉRMINO" DataField="previsao_termino" DataFormatString="{0:dd/MM/yyyy}" HeaderStyle-Width="60px" 
        ItemStyle-HorizontalAlign="Center"> 
        <HeaderStyle Width="60px" /> 
        <ItemStyle HorizontalAlign="Center" /> 
        </asp:BoundField> 
        <asp:BoundField HeaderText="PROJETO" DataField="projeto" ItemStyle-HorizontalAlign="Center"></asp:BoundField> 
        <asp:BoundField HeaderText="FUNCIONALIDADE" DataField="funcionalidade" ItemStyle-HorizontalAlign="Center" /> 
        <asp:BoundField HeaderText="CLUBE" DataField="clube" ItemStyle-HorizontalAlign="Center" /> 

        <asp:TemplateField HeaderStyle-Width="70px" HeaderText="VISUALIZAR" > 
         <ItemTemplate> 
          <asp:Button ID="Btn_Visualizar" runat="server" Text="VISUALIZAR" CssClass="Btn_Grid" Font-Size="7pt" Font-Names="Verdana, Arial" OnClick="Btn_Visualizar_Click" 
          CommandName="visualizar" CommandArgument="<%# ((GridViewRow)Container).RowIndex %>" />        
         </ItemTemplate> 
        </asp:TemplateField> 
        <asp:TemplateField HeaderStyle-Width="66px" HeaderText="ALTERAR"> 
         <ItemTemplate> 
          <asp:Button ID="Btn_Alterar" runat="server" Text="ALTERAR" CssClass="Btn_Grid" Font-Size="7pt" Font-Names="Verdana, Arial" 
          CommandName="editar" CommandArgument="<%# ((GridViewRow)Container).RowIndex %>" /> 
         </ItemTemplate> 
        </asp:TemplateField> 


       </columns> 
      <EditRowStyle ForeColor="Black" CssClass="GridViewEditRow" /> 
      <FooterStyle BackColor="#CCCCCC" /> 
      <HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" BorderColor="White" BorderStyle="Solid" BorderWidth="1px" /> 
      <PagerStyle BackColor="#CCCCCC" ForeColor="Black" HorizontalAlign="Left" /> 
      <RowStyle BackColor="White" /> 
      <SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />  
      </asp:GridView> 

RowwCommand:

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) 
     { 
      if (e.CommandName == "visualizar") 
      { 
       Session["id"] = GridView1.Rows[Convert.ToInt32(e.CommandArgument.ToString())].Cells[0].Text; 
       Session["editar"] = null; 
      } 
      else if (e.CommandName == "editar") 
      { 
       Session["id"] = GridView1.Rows[Convert.ToInt32(e.CommandArgument.ToString())].Cells[0].Text; //Grava o ID do chamado da linha correspondente. 
       Session["editar"] = 1; // 1 - Editar 2 - Não Editar . 
      } 

      Response.Redirect("/Adm/DetalhesChamado.aspx"); 

     } 

觀測數據:正如你可以看到我有一個Button重定向到另一個頁面,當我點擊列進行排序(Btn_Alterar),我重定向到同一頁面。我不知道是否有什麼關係... 謝謝!

回答

0

最可能的是,這是的onrowcommand="GridView1_RowCommand"

+0

Hi @TamalKantiDey。我會做一些改變來測試它,儘快我會留下一個反饋。告訴我,我該怎麼辦? – Ghaleon

+0

如果你提供'GridView1_RowCommand'代碼,會更好。 –

+0

編輯@TamalKantiDey!我想你是對的。 – Ghaleon

0

一個postback.coz回發是因爲onrowcommand="GridView1_RowCommand

onrowcommand附加到GridView時,它會在您點擊它時被激怒。嘗試刪除事件或相應地更新代碼。