本文介绍了如何在asp.net的网格视图中最后移动命令字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我具有动态填充的gridview.其中第一列是命令字段编辑删除.如何最后将此列移到右侧.

i have gridview which is filled dynamically.in which first column is of command field edit delete .how to move this column to the right at last.

推荐答案

<asp:GridView runat="server" AutoGenerateColumns="false" ID="GridViewCustomer">
    <Columns>
        <asp:TemplateField>
            <ItemTemplate>
                <asp:Label Text='<%# Eval("CustomerName") %>' runat="server" />
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField>
            <ItemTemplate>
                <asp:Button ID="Button1" Text="Edit" CommandName="Edit" CommandArgument='<%# Eval("CustomerId") %>'

                    runat="server" />
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>


<body>
    <form id="form1" runat="server">
    <div>
    <asp:GridView ID="Gridview1" runat="server" AllowPaging="true" ShowFooter="true" PageSize="5" AutoGenerateColumns="false" OnPageIndexChanging="Gridview1_PageIndexChanging"

    OnRowCancelingEdit="Gridview1_RowCancelingEdit" OnRowCommand="Gridview1_RowCommand"  OnRowDeleting="Gridview1_RowDeleting"

    OnRowEditing="Gridview1_RowEditing" OnRowUpdating="Gridview1_RowUpdating" HeaderStyle-BackColor="Red"

    HeaderStyle-ForeColor="White" BackColor="#ffffccc">
    <AlternatingRowStyle BackColor="#ffffcc" />
    <Columns>
    <asp:TemplateField HeaderText="EmpID">
    <ItemTemplate>
    <asp:Label ID="lblempid" runat="server" Text='<%#Eval("empid")%>'></asp:Label>
    </ItemTemplate>
    <FooterTemplate>
    <asp:Label ID="lblAdd" runat="server"></asp:Label>
    </FooterTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Name">
    <ItemTemplate>
    <asp:Label ID="lblname" runat="server" Text='<%#Eval("name") %>'></asp:Label>
    </ItemTemplate>
    <EditItemTemplate>
    <asp:TextBox ID="txtname" runat="server" Text='<%#Eval("name") %>'></asp:TextBox>
    </EditItemTemplate>
    <FooterTemplate>
    <asp:TextBox ID="txtAddname" runat="server"></asp:TextBox>
    </FooterTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Address">
    <ItemTemplate>
    <asp:Label ID="lbladdress" runat="server" Text='<%#Eval("address") %>'></asp:Label>
    </ItemTemplate>
    <EditItemTemplate>
    <asp:TextBox ID="txtaddress" runat="server" Text='<%#Eval("address") %>'></asp:TextBox>
    </EditItemTemplate>
    <FooterTemplate>
    <asp:TextBox ID="txtAddaddress" runat="server"></asp:TextBox>
    </FooterTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Designation">
    <ItemTemplate>
    <asp:Label ID="lbldesignation" runat="server" Text='<%#Eval("designation") %>'></asp:Label>
    </ItemTemplate>
    <EditItemTemplate>
    <asp:TextBox ID="txtdesignation" runat="server" Text='<%#Eval("designation") %>'></asp:TextBox>
    </EditItemTemplate>
    <FooterTemplate>
    <asp:TextBox ID="txtAdddesignation" runat="server"></asp:TextBox>
    </FooterTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Create Time">
    <ItemTemplate>
    <asp:Label ID="lblcreatetime" runat="server" Text='<%#Eval("createtime") %>'></asp:Label>
    </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Edit">
    <ItemTemplate>
    <asp:LinkButton ID="btnEdit" runat="server" Text="Edit" CommandName="Edit"></asp:LinkButton><br />
    <span onclick="return confirm('Are You Sure You Want To Delete This Record..?')">
    <asp:LinkButton ID="btnDelete" Text="Delete" runat="server" CommandName="Delete"></asp:LinkButton>
    </span>
    </ItemTemplate>
    <EditItemTemplate>
    <asp:LinkButton ID="btnUpdate" runat="server" Text="Update" CommandName="Update"></asp:LinkButton><br />
    <asp:LinkButton ID="btnCancel" runat="server" CommandName="Cancel" Text="Cancel"></asp:LinkButton>
    </EditItemTemplate>
    <FooterTemplate>
    <asp:Button ID="btnAddRecord" runat="server" Text="Add" CommandName="Add" />
    </FooterTemplate>
    </asp:TemplateField>
    </Columns>
    </asp:GridView>
    </div>
    </form>
</body>


这篇关于如何在asp.net的网格视图中最后移动命令字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 22:24