how to show/hide gridview Columns using javascript

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mudassir368
    New Member
    • Jul 2007
    • 7

    how to show/hide gridview Columns using javascript

    --This is the html code
    [code=html]
    <body>
    <form id="form1" runat="server">
    <div>
    <asp:GridView ID="GridView1" runat="server" AutoGenerateCol umns="False">
    <Columns>
    <asp:TemplateFi eld HeaderText="Age nt Name">
    <ItemTemplate >
    <asp:Label ID="lblagentnam e" runat="server" Text='<%#Bind(" AgentName") %>'></asp:Label>
    </ItemTemplate>
    </asp:TemplateFie ld>
    <asp:TemplateFi eld HeaderText="Age nt Amount">
    <ItemTemplate >
    <asp:Label ID="lblagentAmo unt" runat="server" Text='<%#Bind(" AgentAmount") %>'></asp:Label>
    </ItemTemplate>
    </asp:TemplateFie ld>
    </Columns>
    </asp:GridView>
    &nbsp;<asp:Butt on ID="Button1" runat="server" OnClick="Button 1_Click" Text="Button"/>
    </div>
    </form>
    </body>
    [/code]
    ----This is the csharp code
    [code=asp]
    public partial class GridValidation : System.Web.UI.P age
    {
    protected void Page_Load(objec t sender, EventArgs e)
    {
    DataTable dt = new DataTable();
    dt.Columns.Add( "AgentName" , typeof(string)) ;
    dt.Columns.Add( "AgentAmoun t", typeof(string)) ;
    dt.AcceptChange s();

    DataRow dr = dt.NewRow();
    dr["AgentName"] = "shashikesh mishta";
    dr["AgentAmoun t"] = "1000";
    dt.Rows.Add(dr) ;

    DataRow dr1 = dt.NewRow();
    dr1["AgentName"] = "HAVAK";
    dr1["AgentAmoun t"] = "10001";
    dt.Rows.Add(dr1 );
    dt.AcceptChange s();

    GridView1.DataS ource = dt;
    GridView1.DataB ind();

    }
    protected void Button1_Click(o bject sender, EventArgs e)
    {
    //so on this button click(on client click) i want to hide "Agent Amount"
    //coumn

    }
    }[/code]
    Last edited by pbmods; Jul 24 '07, 05:38 PM. Reason: Added CODE tags.
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5388

    #2
    hi ...

    welcome to TSDN ....

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

    kind regards

    Comment

    • pbmods
      Recognized Expert Expert
      • Apr 2007
      • 5821

      #3
      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.

      Comment

      • mudassir368
        New Member
        • Jul 2007
        • 7

        #4
        Originally posted by pbmods
        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

        Comment

        Working...