Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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:
C#
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:
C#
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
Updated 26-Jan-13 2:41am
v3

Hi,
Can you check the below
C#
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
 
Share this answer
 
@Muthuraja thank you so much it works ...
but my query is in DAL i am accessing it with method like..
public List<tblmainaccount> 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
 
Share this answer
 
Comments
André Kraak 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.
Hi,

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

Please let me know your comments.

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

Regards
Muthuraja Irullandi 27-Jan-13 10:54am    
Great, did you marked the question as answered?
[no name] 27-Jan-13 6:15am    
Improve your solution without adding more than one solutions here.
Muthuraja Irullandi 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)



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