我想在网格视图的行尾添加更新和编辑按钮 [英] I want update and edit button at the end of row in grid view

查看:51
本文介绍了我想在网格视图的行尾添加更新和编辑按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有编辑和删除按钮我希望它在行尾



我尝试过:



< asp:GridView ID =GridView1runat =serverOnRowCommand =GridView1_RowCommandCssClass =table table-responsive>

解决方案

您是否需要gridview中每行末尾的编辑和删除按钮?如果是,请转到youur gridview属性,单击集合,然后选择模板列并选择按钮字段。这应该在行的末尾添加一个按钮。


您可以在<$ c中轻松排列的顺序$ c> GridView 如果将 AutogenerateColumns 属性设置为 false



由于您使用 AutogenerateColumns ,那么您可以尝试这样的事情:

 <   asp:gridview     id   =  GridView1    runat   =  server    onrowcreated   =  GridView1_RowCreated    cssclass   = 表格响应 > ;  
< >
< asp:commandfield showsitbutton = True >
< / asp:commandfield > < / columns >
< / asp:gridview >





Code Behind:

  protected   void  GridView1_RowCreated( object  sender,G ridViewRowEventArgs e){

GridViewRow row = e.Row;
// Intitialize TableCell list
List< tablecell> columns = new List< tablecell>();
foreach (DataControlField列 GridView1.Columns)
{
// 获取第一个Cell / Column
TableCell cell = row.Cells [ 0 ];
// 然后在
row.Cells.Remove(cell)之后将其删除;
// 并将其添加到列表集合
columns.Add(cell );
}

// 添加单元格
行.Cells.AddRange(columns.ToArray());
}
< / tablecell > < / tablecell > ;





上面的代码会将自动生成的列移动到 GridView中最左侧的列


I have edit and delete button i want it at End of row

What I have tried:

<asp:GridView ID="GridView1" runat="server" OnRowCommand="GridView1_RowCommand" CssClass="table table-responsive">

解决方案

Do you need the edit and delete button at the end of each row inside the gridview? if yes, Go to youur gridview properties, click on collections, then select template column and choose button field. That should add a button at the end of the row.


You could easily arrange the order of the Columns within the GridView if you set AutogenerateColumns property to false.

Since you were using AutogenerateColumns, then you could try something like this:

<asp:gridview id="GridView1" runat="server" onrowcreated="GridView1_RowCreated" cssclass="table table-responsive">
    <columns>
      <asp:commandfield showeditbutton="True">
    </asp:commandfield></columns>
</asp:gridview>



Code Behind:

protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e){

        GridViewRow row = e.Row;
        // Intitialize TableCell list
        List<tablecell> columns = new List<tablecell>();
        foreach (DataControlField column in GridView1.Columns)
        {
            //Get the first Cell /Column
            TableCell cell = row.Cells[0];
            // Then Remove it after
            row.Cells.Remove(cell);
            //And Add it to the List Collections
            columns.Add(cell);
        }

        // Add cells
        row.Cells.AddRange(columns.ToArray());
}
</tablecell></tablecell>



The code above will move the autogenerated columns to the left most column in your GridView.


这篇关于我想在网格视图的行尾添加更新和编辑按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆