Sunday, 15 July 2012

How to join multiple table's data in one GridView in ASP.Net Webform on button_click -



How to join multiple table's data in one GridView in ASP.Net Webform on button_click -

i populating transaction info on 1 button click in gridview. however, transaction table in database not contain dimension table (e.g. business relationship table) info such transaction table contains accountid not have accountname property have bring business relationship table. in dataaccess layer method (getalltransactions()) contain bring together between transaction , business relationship table on accountid, when seek select account.accountname not work.

i need show few tables transaction table accountid mataches , show accountname column instead of accountid transaction table.

the dataaccess method looks like:

public static ienumerable<transaction>getalltransactions() { list<transaction> alltransactions = new list<transaction>(); using (var context = new costreportentities()) { alltransactions = (from t in context.transactions bring together business relationship in context.accounts on t.accountid equals account.accountid select t).tolist(); } homecoming alltransactions; }

and code behind .aspx page follows:

protected void _uibuttonsubmit_click(object sender, eventargs e) { ienumerable<transaction> transactions = ts.getalltransactions(); _uitransactiongridview.datasource = transactions; _uitransactiongridview.databind(); _uitransactiongridview.pageindex = 0; }

tried few things next also, not getting linq idea. next gives error.

...select new {t.*, account.accountname}).tolist();

i need direction way should looking @ create task work populate info multiple tables in 1 gridview. thanks.

since model transaction did not have property of business relationship table had create viewmodel type class returns custom info of accountnumber every transaction.

tha code used solve problem this

asp.net gridview linq-to-entities

No comments:

Post a Comment