Click here to Skip to main content
15,903,523 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello Friends , I am Using a Gridview In That Gridview There Is Two Column StudentName And Address This Two Columns Comes From StudentInfo Table. I Want To Merge Third Column In Same Gridview which Comes From Differant Table. This Table Name Is BooksInfo , How Would I Impliment Please Help Me....
Posted
Updated 23-Dec-15 2:31am
v2

1 solution

There are really several options for performing this type of 'merger', but here are a couple.

Update the DataSource of your GridView Control
The simplest method is to update the DataSource so that it includes all of the fields you are looking for. If you are using a DataTable or DataReader as the DataSource of the control, update your query to include the data from the BooksInfo table.

Another option is to create your own data model that would include all three fields and use that as the DataSource. The model might look something like:

<br />
public class GridViewDataSource<br />
{<br />
public string StudentName { get; set; }<br />
public string Address { get; set; }<br />
public string BooksInfoData { get; set; }<br />


Once you have performed your query and populated a List<gridviewdatasource>, you can use that list as the DataSource of the GridView control.

Use a TemplateField and the RowDataBound event
If you subscribe to the RowDataBound event, it will provide you with the information about the row and the bound data element. Using that information, you could then lookup the information in the BooksInfo table, and update the TemplateField with the appropriate data from the results of your lookup.
 
Share this answer
 

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