Click here to Skip to main content
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 OriginalGriff 540
1 Sergey Alexandrovich Kryukov 402
2 Yogesh Kumar Tyagi 384
3 Prakriti Goyal 280
4 Maciej Los 205
0 OriginalGriff 6,632
1 Sergey Alexandrovich Kryukov 5,404
2 Maciej Los 3,474
3 Peter Leow 3,299
4 DamithSL 2,495


Advertise | Privacy | Mobile
Web01 | 2.8.140721.1 | Last Updated 26 Jan 2013
Copyright © CodeProject, 1999-2014
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