Click here to Skip to main content
15,891,702 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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.
Posted
Comments
Sergey Alexandrovich Kryukov 19-Oct-12 12:44pm    
What does it mean: "at last"? It's not clear what you want, exactly.
--SA
Member 9334390 21-Oct-12 3:36am    
i have auto generate column edit at first column of gridview...i want this column as last column of gridview.note here gridview is filled at runtime
Member 9334390 21-Oct-12 3:41am    
i have a autogenerated column edit as first column of gridview.i want this column ats last column of gridview.note here
Sandeep Mewara 19-Oct-12 13:11pm    
This is not a well framed question! We cannot work out what you are trying to do/ask from the post. Please elaborate and be specific.
Use the "Improve question" link to edit your question and provide better information.
Ram Sagar Mourya 20-Oct-12 1:12am    
i guess he has Edit and Delete Command fields in the first column and he wants them to be in the last column.

Dont be depend on AutoGenerate COlumns,

Use TemplateField as
XML
<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>
 
Share this answer
 
Comments
[no name] 20-Oct-12 5:05am    
my 5
Marla Sukesh 20-Oct-12 5:07am    
thanks Mits
You can design like this :-

XML
<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>
 
Share this answer
 
Comments
[no name] 20-Oct-12 5:06am    
my 5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900