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

Nested GridView [No JavaScripts]

Rate me:
Please Sign up or sign in to vote.
4.15/5 (11 votes)
19 Jul 2009CPOL3 min read 68.5K   2.7K   51  
Nesting GridViews without writing any JavaScript code [AJAX driven].
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Data.Sql;
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 order_view : System.Web.UI.Page
{
    SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["IVN_sysConnectionString"].ConnectionString);
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        LinkButton l_btn = (LinkButton)sender;
        GridViewRow gvr = (GridViewRow)l_btn.NamingContainer;
        Panel p1 = (Panel)gvr.FindControl("Panel1");
        LinkButton lb1 = (LinkButton)gvr.FindControl("LinkButton1");
        if (p1.Visible == false)
        {
            p1.Visible = true;
            lb1.Text = "-";
        }
        else if (p1.Visible == true)
        {
            p1.Visible = false;
            lb1.Text = "+";
        }
        GridView gv2 = (GridView)l_btn.FindControl("GridView2");
        gv2.DataBind();
    }

    protected void GridView2_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            SqlDataSource s = (SqlDataSource)e.Row.FindControl("SqlDataSource2");
            s.SelectParameters[0].DefaultValue = e.Row.Cells[1].Text;
        }
        DataSet dss = new DataSet();
        SqlDataAdapter daa = new SqlDataAdapter("SELECT order_status_overall FROM orders WHERE order_no='" + e.Row.Cells[1].Text + "';", conn);
        daa.Fill(dss);
        string x = "Not Received";
        int y=0;
        //foreach(DataRow drr in dss.Tables[0].Rows)
            foreach(DataRow drr in dss.Tables[0].Rows)
             {
            y=string.Compare(drr[0].ToString(),x.ToString());
            if(y==0)
            {
                e.Row.BackColor = System.Drawing.Color.LightPink;
            }
        }
    }
    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
}

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
Saudi Arabia Saudi Arabia
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions