Click here to Skip to main content
15,895,799 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have gridview i want to remove column in gridview in that session only. if i click on delete button that perticular column is deleted.in footer i put delete button per every column.
Posted
Updated 29-Mar-15 23:49pm
v2
Comments
Sinisa Hajnal 30-Mar-15 6:38am    
What is the problem? Please show some code of what you've tried and try to explain a bit better what do you need...I mean, you already know which button is clicked (and in which column) so delete based on that.
Member 11565624 30-Mar-15 7:06am    
take one gridview .put the delete button in every column of footertemplate.we click on delete button that column is deleted temperarely.

Hi, hope according your query this link will help.

Thanks in advance.

Show / Hide GridView Columns in ASP.NET[^]
 
Share this answer
 
Comments
Member 11565624 30-Mar-15 7:10am    
here u take dropdownlist. i take delete button for every column of footer template .we click on delete button that column is deleted.First we find column index based on column index we delete the column.
Kindly elaborate your question with some sample of your codes.
 
Share this answer
 
Comments
Member 11565624 30-Mar-15 7:13am    
<asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333"
GridLines="None" AutoGenerateColumns="False" ShowFooter="True"
Height="120px"
>

<alternatingrowstyle backcolor="White">
<columns>

<asp:TemplateField HeaderText="personid" SortExpression="personid"
>

<edititemtemplate>
<asp:Label ID="pid" runat="server" Text='<%# Bind("personid") %>'>


<footertemplate>
<asp:Button ID="Button1" runat="server" Text="Delete" OnClick="Button1_Click" />
<%-- <asp:CheckBox ID="CheckBox1" runat="server" />--%>


<itemtemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("personid") %>'>


<asp:TemplateField HeaderText="Addressid" SortExpression="Addressid">
<edititemtemplate>
<asp:TextBox ID="addid" runat="server" Text='<%# Bind("Addressid") %>'>

<footertemplate>
<asp:Button ID="Button2" runat="server" Text="Delete" onclick="Button2_Click" />

<itemtemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("Addressid") %>'>


<asp:TemplateField HeaderText="FirstName" SortExpression="FirstName">
<edititemtemplate>
<asp:TextBox ID="fname" runat="server" Text='<%# Bind("FirstName") %>'>

<footertemplate>
<asp:Button ID="Button3" runat="server" Text="Delete" onclick="Button3_Click" />

<itemtemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("FirstName") %>'>


<asp:TemplateField HeaderText="CreatedDate" SortExpression="CreatedDate">
<edititemtemplate>
<asp:TextBox ID="cdate" runat="server" Text='<%# Bind("CreatedDate") %>'>

<footertemplate>
<asp:Button ID="Button4" runat="server" Text="Delete" onclick="Button4_Click" />

<itemtemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Bind("CreatedDate") %>'>


<asp:TemplateField HeaderText="LastName" SortExpression="LastName">
<edititemtemplate>
<asp:TextBox ID="lname" runat="server" Text='<%# Bind("LastName") %>'>

<footertemplate>
<asp:Button ID="Button5" runat="server" Text="Delete" onclick="Button5_Click" />

<itemtemplate>
<asp:Label ID="Label5" runat="server" Text='<%# Bind("LastName") %>'>



<asp:Tem
upendra shahi 30-Mar-15 7:54am    
How do you want to implement this? either code behind or with JQuery, do you want page postback on button click?
You can get column index by JQuery which starts from 0..

with code

IN GridView RowDataBound event


DataRowView tableData = e.Row.DataItem as DataRowView;
int pos = tableData.GetIndex("MyFieldName");
Member 11565624 30-Mar-15 8:06am    
whenever we click on delete button that column is deleted.don't use field name.some times column name is changed again we go to code and change the column name.no need to do that.

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