Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

need help in nesting gridview

Last post 07-05-2008 4:55 PM by TimL. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 07-03-2008 7:37 AM

    need help in nesting gridview

     Hi,

     I am new to gridview control. have nested a gridview inside another gridview. The address details in the child gridview is repeating  for all users(candidate name)  and I m not  getting corresponding address for each users.
    Plz help me as soon as possible.. here is the code have
     
    // Parent Gridview Binding
    public void BindData()
        {

               SqlConnection con=new SqlConnection("Server:localhost;Uid=;Password=;Database="Employee");
              SqlCommand cmd=new SqlCommand("Select * from Employee",con);
              SqlDataAdapter da=new SalDataAdapter();
               Dataset ds=new DataSet();
               da.Fill(ds);
     
            ParentGrid.DataSource = ds.Tables[0] ;
            ParentGrid.DataBind();
      
        
        }


    //Child Gridview Binding


     protected void ParentGrid_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {


           SqlConnection con=new SqlConnection("Server:localhost;Uid=;Password=;Database="Employee");
               SqlCommand cmd=new SqlCommand("Select Address,Mobile from Employee",con);
               SqlDataAdapter da=new SalDataAdapter();
               Dataset ds=new DataSet();
               da.Fill(ds);
        
                GridView gv2 = new  GridView();

                (GridView)gv2 = ( GridView)e.Row.FindControl("ChildGrid");

               
                gv2.DataSource = ds.Tables[0];
                gv2.DataBind();

            }
    }

    img 

    • Post Points: 10
  • Advertisement

    • Red Gate Software

    Advertisement

    Want to boost your .NET application performance?

    Some developers always seem to write efficient and lightening-fast code. What is their secret? It’s ANTS Profiler. “We improved the performance of the application up to 10 times” Dan Ports, Intrigma.

    Try it for yourself now.

  • 07-03-2008 9:52 PM In reply to

    • TimL
    • Top 100 Contributor
    • Joined on 07-02-2007
    • United Kingdom
    • Fanatic Member
    • Points 1,540

    Re: need help in nesting gridview

    mr_rajesh86:
    SqlCommand cmd=new SqlCommand("Select Address,Mobile from Employee",con);

    It’s probably because you’re missing a ‘where’ clause on the line above.

    mr_rajesh86:
               SqlCommand cmd=new SqlCommand("Select Address,Mobile from Employee",con);
               SqlDataAdapter da=new SalDataAdapter();
               Dataset ds=new DataSet();
               da.Fill(ds);
     

    You're also not associating cmd with da so you need to say:

    da.SelectCommand = cmd;

    or initialise ds like so:

    Dataset ds=new DataSet(cmd);
     

     

    • Post Points: 10
  • 07-05-2008 3:18 PM In reply to

    Re: need help in nesting gridview

    hi.

        Thanks a lot. 

    • Post Points: 10
  • 07-05-2008 4:55 PM In reply to

    • TimL
    • Top 100 Contributor
    • Joined on 07-02-2007
    • United Kingdom
    • Fanatic Member
    • Points 1,540

    Re: need help in nesting gridview

    No worries Smiley Face

    • Post Points: 5
Page 1 of 1 (4 items)