View Single Post
  #1 (permalink)  
Old April 13th, 2006, 04:28 AM
ziaiz ziaiz is offline
Registered User
 
Join Date: Jul 2005
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default HOWTO Nested Grid in ASP.Net 2.0???

Problem 1:

i want nesting of grids like in hierarchical format (Expand-collapse) in ASP.Net 2.0, is there any trick to do that without heavy javascript or HTML? is there any way to do that using new GridView control?

i have done something like this (http://www.samspublishing.com/conten...inks/fig04.jpg)

but i want the child grid only show when i click the select button( itemcommand event) of the parent grid and only current row display the child grid not others...

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%


Problem 2:

another example i tried is http://msdn.microsoft.com/msdnmag/is...0/CuttingEdge/

it has the proper format what i want but when i connect it with my sql server data it is showing me error: "The relation is not parented to the table to which this DataView points"

my tables are:

tbl1:

RegionCode -RegionName
R1 -North Region
R2 -Mumbai Region
R3 -East Region
R4 -South Region
R5 -Gujarat Region
R6 -Maharashtra Region

tbl2:

RegionCode -ZoneCode -ZoneName
R1 -R1Z1 -Delhi NCR
R1 -R1Z2 -U.P, Bihar & Uttaranchal
R1 -R1Z3 -Haryana
R1 -R1Z4 -Punjab
R1 -R1Z5 -Chandigarh
R1 -R1Z6 -M.P.
R1 -R1Z7 -Jaipur
R2 -R2Z1 -Mumbai
R3 -R3Z1 -Kolkatta
R3 -R3Z2 -Rest of East




code is:

protected void Page_Load(object sender, System.EventArgs e)
        {
            // Put user code to initialize the page here
            if (!IsPostBack)
            {
                SqlDataAdapter adapter = new SqlDataAdapter(
    "SELECT * from tbl1", "SERVER=local;DATABASE=mydata0607;UID=sa;pwd=s a");

    SqlDataAdapter adapter1 = new SqlDataAdapter("select * from tbl2", "SERVER=local;DATABASE=mydata0607;UID=sa;pwd=s a");

                DataSet data = new DataSet();
                adapter.Fill(data, "tbl1");
                adapter1.Fill(data, "tbl2");

                data.Tables[0].TableName = "tbl1";
                data.Tables[1].TableName = "tbl2";


                string relName = "tbl12tbl2";
                DataRelation rel = new DataRelation(relName,
                    data.Tables["tbl1"].Columns["RegionCode"],
                    data.Tables["tbl2"].Columns["RegionCode"]);
                data.Relations.Add(rel);

                                Cache["MyData"] = data;
            }

            BindData();
    }


        protected void UpdateView(object sender, System.EventArgs e)
        {
            BindData();
        }


        private void BindData()
        {
            // Bind the data source
            dataGrid.DataSource = (DataSet) Cache["MyData"];
            dataGrid.DataMember = "tbl1";

            // Bind the data
            dataGrid.DataBind();
        }



//'please help me...:(