2013-05-22 2 views
1

나는 totatly programatically에 의해 묶여있는 gridview 있습니다. 그리고 나는 선택을위한 명령 필드를 추가했습니다. 그러나 그것은 첫 번째 열에 나타납니다. 내가 마지막 열의 순서를 변경하고 싶습니다. Displayindex를 사용하려고했지만 해당 열은 headerrow를 포함하지 않습니다.gridview에서 commandField의 순서를 변경 하시겠습니까?

여기 난 그냥

  UserID UserName UserAddress 
    ------------------------------------------------- 
      1  testname testaddress Select 


<asp:GridView ID="GridForUnits" runat="server" CellPadding="4" ForeColor="#333333" 
         GridLines="None" Style="text-align: left" Width="851px" OnRowDataBound="GridForUnits_RowDataBound" 
         OnSelectedIndexChanged="GridForUnits_SelectedIndexChanged1"> 
         <AlternatingRowStyle BackColor="White" /> 
         <Columns> 
          <asp:CommandField ShowSelectButton="True" /> 
         </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> 

어떤 도움 감사합니다 마지막 열을 선택 전달하려는

  UserID UserName UserAddress 
    ------------------------------------------------- 
    Select 1  testname testaddress 

처럼 내 gridview에 보이는 것입니다. 나는 자동 선택 버튼을 마지막 설정, 열을 생성 수동으로 작성하고 그들 모두의 눈에 보이는 인덱스를 변경하지 권 해드립니다 것이다

감사

+1

당신이있는 gridview에 대한 귀하의 마크를 게시 할 수 있습니까? –

+0

ok – user2375896

+0

어떻게 데이터 바인딩을 수행하고 있습니까? SQL 데이터 소스에서 데이터 테이블에 바인딩합니까? 모든 관련 코드를 게시 할 수 있습니까? –

답변

0

.

More explanation here

다른 해결 방법 : RowDataBound 이벤트에 주위 TableCells 이동 :

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) 
    { 
     GridViewRow row = e.Row; 


     List<TableCell> cells = new List<TableCell>(); 


     foreach (DataControlField column in GridView1.Columns) 
     { 
      // Retrieve first cell 
      TableCell cell = row.Cells[0]; 


      // Remove cell 
      row.Cells.Remove(cell); 


      // Add cell to list 
      cells.Add(cell); 
     } 


     // Add cells 
     row.Cells.AddRange(cells.ToArray()); 
    } 

Link to source

+0

BuT 이것은 완전히 구성 가능한 프로젝트의 일부이며 열 이름과 크기가 변경 될 수 있습니다. – user2375896

+0

Ok. 열에 액세스 할 수있는 헤더 텍스트를 넣으면 어떻게됩니까? 특정 열의 순서를 변경하는 것이 더 쉬운가? – user2375896

+0

내 대답을 확인하고 업데이트했습니다. – AAlferez

관련 문제