Click here to Skip to main content
15,891,864 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
hi
i have 2 gridview tables... 1 is populated from a dropdown list by datbound.e.g when the user select tameside cc from the dropdown list all the details about tameside that are saved on the database are displayed in the gridview below. One column is their companyID,
now i need to populate my second gridview table with the companyID from the selected FIrst gridview table, if the companyID in the Second gridview is blank. Does anyone know how i can do this please

so far i can change the colour of the background if the companyid in second gridview is blank using the following code:

VB
If (e.Row.Cells(11).Text = "" Or e.Row.Cells(11).Text = " ") Then
          e.Row.Cells(11).BackColor = System.Drawing.Color.Salmon
          importButtonEnabled = False
      End If

thanks for any help :-)
Posted
Comments
[no name] 30-Jun-11 14:43pm    
Sorry, I'm not quite with you. I get the dropdown selection initiating a database call that populates the first gridview. And I understand using the CompanyID to load a second gridview. It's the "...if the CompanyID in the second gridview is blank" part that I don't quite see. Is the second gridview already populated from somewhere else?
reid0588 1-Jul-11 6:17am    
hi sorry if i did not make myself clear. what i am attempting to do is upload a file from excel to sql server. the user must first select the company that the excel file belongs to (using the dropdown lists), once this has been done, a grdiview displays the information with regards to that company e.g their companyID. NOw when the user selects the excel file to upload, the company will not have added their company ID as this is just something we use,so this will be blank, however in order for it to load to the sql server correctly the companyID in the file must be populated. so when they upload the excel file, view it...the companyid in grdiview 2 will automatically be populated from the gridview 1 companyID. I had it before that the user would see an error with the file and then change the file themselves, however my boss did not like this and wanted it auto generated. is there a way to do it please. Sorry for the late response
reid0588 1-Jul-11 7:14am    
hi...i can get the data to copy from the cell, however it only copies into the first cell, i need it to copy into the entire column. Can anyone help please?

If (e.Row.Cells(11).Text = "" Or e.Row.Cells(11).Text = " ") Then
e.Row.Cells(11).Text = GridCompany.DataKeys(e.Row.RowIndex)("compDataID").ToString()
Viral Upadhyay 1-Jul-11 8:08am    
where you have use this code?
Use it on rowdatabound method will solve your problem.

1 solution

hi many thanks for all the help, i have manage to sort it now using the following code.
VB
If (e.Row.Cells(11).Text = "" Or e.Row.Cells(11).Text = " ") Then
    e.Row.Cells(11).Text = GridCompany.DataKeys(0)("compDataID").ToString()
End If
 
Share this answer
 
Comments
RaviRanjanKr 1-Jul-11 16:49pm    
Nice Answer! My 5 :)

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900