Problem with DataGrid

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Mar 2008
Posts: 268
Reputation: Traicey is an unknown quantity at this point 
Solved Threads: 19
Traicey's Avatar
Traicey Traicey is offline Offline
Posting Whiz in Training

Problem with DataGrid

 
0
  #1
Dec 3rd, 2008
I have 2 datagrid, 1 with details of Category and the other with the products user selected from the other datagrid, what Im saying is I have a select command on my 1st datagrid so when I select something from my 1st datagrid it should be added to the 2nd datagrid and that is workin but the problem is everytime I select somethin from the 1st datagrid adding to the 2nd datagrid it overwrites the existing record on the 2nd datagrid instead of adding on top of... can anyone help me please here the code to add what is from the 1st grid to the second one

  1. imgItems.ImageUrl = "Pictures/" + dgItems.SelectedItem.Cells[2].Text;
  2. string strDetails = "sdp_ViewProducts";
  3. //CommandType.StoredProcedure;
  4. DataSet dsDetails = new DataSet();
  5. SqlDataAdapter daDetails = new SqlDataAdapter(strDetails, conn);
  6. daDetails.SelectCommand.CommandText = "Select ProductID, ProductName, UnitPrice, UnitsInStock, UnitsOnOrder from dbo.Products where ProductID = " +
  7. dgItems.SelectedItem.Cells[1].Text;
  8.  
  9. daDetails.Fill(dsDetails, "Products");
  10. dgDetails.DataSource = dsDetails;
  11. dgDetails.DataMember = "Products";
  12. dgDetails.DataKeyField = "ProductID";
  13. dgDetails.DataBind();
  14. dgDetails.Visible = true;

Thanx in advance
Some people get so rich they lose all respect for humanity. That's how rich I want to be.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 34
Reputation: vizy is an unknown quantity at this point 
Solved Threads: 6
vizy's Avatar
vizy vizy is offline Offline
Light Poster

Re: Problem with DataGrid

 
0
  #2
Dec 3rd, 2008
Hi...
The code you are following does overwrites the Grid.

What you can do is
- Copy the data getting from the dsDetails.Table[0] into the DataTable
- Copy that Datatable into the session
- and then merge that datatable coming from dsDetails.Table[0] with the session Datatable everytime
- then Bind the Datatable from the session into dgDetails
Njoy koding... >>>
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 268
Reputation: Traicey is an unknown quantity at this point 
Solved Threads: 19
Traicey's Avatar
Traicey Traicey is offline Offline
Posting Whiz in Training

Re: Problem with DataGrid

 
0
  #3
Dec 4th, 2008
That could be the problem, but then can you provide me with the code similar to that, coz Im clueless what ur talking about

Thanx hey
Some people get so rich they lose all respect for humanity. That's how rich I want to be.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 63
Reputation: 4advanced is an unknown quantity at this point 
Solved Threads: 10
4advanced 4advanced is offline Offline
Junior Poster in Training

Re: Problem with DataGrid

 
0
  #4
Dec 4th, 2008
You might want to put the datasource of datagridview2 into a viewstate and read it back after Page.IsPostBack.

That aint hard to manage....

  1. ' general declarations
  2. dtMemory as datatable=new datatable("YouNameIt")
  3.  
  4. ' In the PageLoad_Event() :
  5. if page.ispostback then
  6. dtMemory = ctype(Viewstate("TEST"), datatable)
  7. else
  8. dtMemory = tblAdapter.Fill(blablabla)
  9. ViewState("TEST") = dtMemory
  10. end if
  11.  
  12. DataGridView2.datasource = dtMemory
  13. DataGridView2.datakeynames = new string() {"Your_ID_Field_Name}
  14. DataGridView2.databind
  15.  

After the ispostback is checked you can add records to the dtMemory datatable for each field the user has selected.....
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC