Click here to Skip to main content
15,892,674 members
Articles / Web Development / ASP.NET

Show Hide Grid Content using Server side(.Net) and Client side(JQuery)

Rate me:
Please Sign up or sign in to vote.
4.87/5 (15 votes)
18 Jul 2017CPOL3 min read 61.8K   916   29  
Handling controls inside GridView using RowCommand and jQuery.
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class GridviewNestedContorls_Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            load_gridviewrecords();
        }
    }
    private void load_gridviewrecords()
    {
        DataTable dt = new DataTable();
        dt.Columns.Add("jobid");
        dt.Columns.Add("jobtitle");
        dt.Columns.Add("positions");
        dt.Columns.Add("Description");
        DataRow dr1 = dt.NewRow();
        dr1["jobid"] = "JOB122";
        dr1["jobtitle"] = "Software Engineer";
        dr1["positions"] = "10";
        dr1["Description"] = "This job not direct. You have to apply through online. Qualification required BE (Computer Science), M.Tech(Computer Science), MCA. Year of passout 2011, 2012.";
        dt.Rows.Add(dr1);
        DataRow dr2 = dt.NewRow();
        dr2["jobid"] = "JOB123";
        dr2["jobtitle"] = "Associate System Engineer";
        dr2["positions"] = "100";
        dr2["Description"] = "This job not direct. You have to apply through online. Basic knowledge of web development. Qualification required BE (Computer Science), M.Tech(Computer Science), MCA. Year of passout 2011, 2012.";
        dt.Rows.Add(dr2);
        DataRow dr3 = dt.NewRow();
        dr3["jobid"] = "JOB124";
        dr3["jobtitle"] = "Web designer";
        dr3["positions"] = "5";
        dr3["Description"] = "This job not direct. You have to apply through online. Required skills css, Jquery, Html, Photoshop. Qualification required BE (Computer Science), M.Tech(Computer Science), MCA. Year of passout 2011, 2012.";
        dt.Rows.Add(dr3);
        dt.AcceptChanges();
        GridView1.DataSource = dt;
        GridView1.DataBind();
        
    }
    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "showhide")
        {
            int index = int.Parse(e.CommandArgument.ToString());
            GridViewRow gr = GridView1.Rows[index];
            ImageButton imgbtn = (ImageButton)gr.FindControl("ImageButton1");
            Panel pnl = (Panel)gr.FindControl("pnlOrders");
            if (pnl.Visible == false)
            {
                imgbtn.ImageUrl = "minus.jpg";
                pnl.Visible = true;
            }
            else
            {
                imgbtn.ImageUrl = "plus.jpg";
                pnl.Visible = false;
            }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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


Written By
Software Developer Sonata Software Pvt Ltd
India India
Hi.. I am Vinod Kumar B C from Mysore, Karnataka. I have done MCA and currently working as a Software Engineer having 3 Years of Experience in web development. I know Asp.net, C#, MVC, Sql Server, CSS, JQuery, C, C++, HTML, DB2, DataStructures.

Comments and Discussions