简体   繁体   English

网格视图动态生成的列

[英]Grid View Dynamically Generated Column

I have Grid View which is dynamically binded with datatables. 我有与数据表动态绑定的网格视图。

I had to add in the last column a command field AAddOn 我必须在最后一列中添加命令字段AAddOn

When trying like below method..AAddOn is displayed at first.. 当像下面的方法尝试时..AAddOn首先显示。

How can we display the command field at the last.. 我们如何在最后显示命令字段。

  <asp:GridView ID="AGridView" runat="server" AutoGenerateColumns="true"  style="table-layout:fixed;" Width="2000px"   RowStyle-HorizontalAlign="Left">
            <EmptyDataTemplate>
               &nbsp;
           </EmptyDataTemplate>
            <asp:CommandField ShowEditButton="True" ItemStyle-Width="80px" EditText="Edit Add On">
             <ItemStyle Font-Bold="true" Font-Size="Small" />
              <HeaderStyle CssClass="AAddOn" />
             </asp:CommandField>
      </asp:GridView>

For gridview, defined columns always render first then the auto generated columns render on the right side of it. 对于gridview,始终先渲染定义的列,然后在其右侧渲染自动生成的列。 To move auto generated columns to left side, you need RowCreated event. 要将自动生成的列移到左侧,您需要RowCreated事件。 There you can manipulate the order of columns as required. 在那里您可以根据需要操纵列的顺序。 You can use below code. 您可以使用以下代码。

protected void AGridView_RowCreated(object sender, GridViewRowEventArgs e){
        List<TableCell> cellColumns = new List<TableCell>();
        foreach (DataControlField column in GridView1.Columns)
        {
            TableCell cell = e.Row.Cells[0];
            e.Row.Cells.Remove(cell);
            cellColumns.Add(cell);
        }

        e.Row.Cells.AddRange(cellColumns .ToArray());
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM