Click here to Skip to main content
11,707,470 members (79,657 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET LINQ
Hi all,

I have a form which has a drop down. I would to fill some text boxes and a drop down based on its result it will fetch data from a database.

I am using Linq query. It returns a row which I receive in a grid view, this works fine, but I would the result in individual text boxes.
Here is my query:
var query = (from m in _db.tblMainAccounts.ToList()
                         where m.MainAccount == mcode
                         select new tblMainAccount
                         {
                             MainAccount = m.MainAccount,
                             Title = m.Title,
                             ControlLevel = m.ControlLevel,
 
                         }).ToList();
            return query;

and in aspx.cs page:
gvCoa.DataSource = coaDal.GetMainAccountWithCode(code);
            gvCoa.DataBind()

Now how do I get the data in text boxes instead of a grid view?

Thanks in advance
Posted 26-Jan-13 2:33am
Edited 26-Jan-13 2:41am
v3
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi,
Can you check the below
var query = from m in _db.tblMainAccounts.ToList()
                         where m.MainAccount == mcode
                         select new tblMainAccount
                         {
                             MainAccount = m.MainAccount,
                             Title = m.Title,
                             ControlLevel = m.ControlLevel,
 
                         };
 
foreach (var item in query) 
{ 
    textbox1.Text= item.MainAccount; 
    textbox2.Text= item.Title; 
    textbox3.Text= item.ControlLevel; 
}

Best Regards
Muthuraja
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

@Muthuraja thank you so much it works ...
but my query is in DAL i am accessing it with method like..
public List GetMainAccountWithCode(string code)
{//code}

now the solution you proposed does work when query is in code behind...
how can i get result via method and then use foreach like you said to show result in text box...

do i need to get the result in list and then use foreach on it..??

regards
Wardah
  Permalink  
Comments
André Kraak at 26-Jan-13 11:23am
   
I think you intended to comment to a solution, but created a solution instead.

If you have a question about or comment on a given solution use the "Have a Question or Comment?" option beneath the solution. When using this option the person who gave the solution gets an e-mail message and knows you placed a comment and can respond if he/she wants.
Please move the content of this solution to the solution you are commenting on and remove the solution.

Thank you.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Hi,

Can you store those value in the List or a Class variable, so that you can return either List or a Class from your GetMainAccountWithCode() method.

Please let me know your comments.

Best Regards
Muthuraja
  Permalink  
Comments
Member 7735818 at 26-Jan-13 11:57am
   
thanks a lot its working now.... :)

Regards
Muthuraja Irullandi at 27-Jan-13 10:54am
   
Great, did you marked the question as answered?
Muthuraja Irullandi at 27-Jan-13 10:55am
   
Sure, I will follow that in future.
Thanks!

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

  Print Answers RSS
0 Maciej Los 195
1 Mika Wendelius 190
2 OriginalGriff 156
3 Sergey Alexandrovich Kryukov 145
4 chainerlt 110
0 OriginalGriff 9,178
1 Sergey Alexandrovich Kryukov 8,562
2 CPallini 5,189
3 Maciej Los 4,806
4 Mika Wendelius 3,706


Advertise | Privacy | Mobile
Web01 | 2.8.150819.1 | Last Updated 26 Jan 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100