By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,640 Members | 1,600 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,640 IT Pros & Developers. It's quick & easy.

how to show/hide gridview Columns using javascript

P: 7
--This is the html code
Expand|Select|Wrap|Line Numbers
  1. <body>
  2.     <form id="form1" runat="server">
  3.         <div>
  4.             <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
  5.                 <Columns>
  6.                     <asp:TemplateField HeaderText="Agent Name">
  7.                         <ItemTemplate>
  8.                             <asp:Label ID="lblagentname" runat="server" Text='<%#Bind("AgentName") %>'></asp:Label>
  9.                         </ItemTemplate>
  10.                     </asp:TemplateField>
  11.                     <asp:TemplateField HeaderText="Agent Amount">
  12.                         <ItemTemplate>
  13.                             <asp:Label ID="lblagentAmount" runat="server" Text='<%#Bind("AgentAmount") %>'></asp:Label>
  14.                         </ItemTemplate>
  15.                     </asp:TemplateField>
  16.                 </Columns>
  17.             </asp:GridView>
  18.             &nbsp;<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button"/>
  19.             </div>
  20.     </form>
  21. </body>
  22.  
----This is the csharp code
Expand|Select|Wrap|Line Numbers
  1. public partial class GridValidation : System.Web.UI.Page
  2. {
  3.     protected void Page_Load(object sender, EventArgs e)
  4.     {
  5.         DataTable dt = new DataTable();
  6.         dt.Columns.Add("AgentName", typeof(string));
  7.         dt.Columns.Add("AgentAmount", typeof(string));
  8.         dt.AcceptChanges();
  9.  
  10.         DataRow dr = dt.NewRow();
  11.         dr["AgentName"] = "shashikesh mishta";
  12.         dr["AgentAmount"] = "1000";
  13.         dt.Rows.Add(dr);
  14.  
  15.         DataRow dr1 = dt.NewRow();
  16.         dr1["AgentName"] = "HAVAK";
  17.         dr1["AgentAmount"] = "10001";
  18.         dt.Rows.Add(dr1);
  19.         dt.AcceptChanges();
  20.  
  21.         GridView1.DataSource = dt;
  22.         GridView1.DataBind();    
  23.  
  24.     }
  25.     protected void Button1_Click(object sender, EventArgs e)
  26.     {
  27.        //so on this button click(on client click) i want to hide "Agent Amount"
  28. //coumn
  29.  
  30.     }
  31. }
Jul 24 '07 #1
Share this Question
Share on Google+
3 Replies


gits
Expert Mod 5K+
P: 5,353
hi ...

welcome to TSDN ....

please post some example-code or a link to a test-page ...

kind regards
Jul 24 '07 #2

pbmods
Expert 5K+
P: 5,821
Heya, mudassir368.

Please use CODE tags when posting source code. See the REPLY GUIDELINES on the right side of the page next time you post.

What do you want your code to do? Give an example.
What is your code doing that you don't want it to do? Give an example.
What is your code *not* doing that it is supposed to? Give an example.
Jul 24 '07 #3

P: 7
Heya, mudassir368.

Please use CODE tags when posting source code. See the REPLY GUIDELINES on the right side of the page next time you post.

What do you want your code to do? Give an example.
What is your code doing that you don't want it to do? Give an example.
What is your code *not* doing that it is supposed to? Give an example.
Hi pbmods,
Right Now My Code is Displaying A gridView with Two Columns
One is "Agent Name" and other is "Agent Amount"
i want a javascript function which will be called on Button1 Click
and it will hide Agent Amount Columns and show only one column
that is Agent Name
This can be easily Done on serve side code
but i want it to be done on client side code
Jul 25 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.