在文本框中获取查询结果并下拉 [英] Get query result in text boxes and Drop down

查看:78
本文介绍了在文本框中获取查询结果并下拉的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我有一张下拉的表格。我想填写一些文本框和基于其结果的下拉列表,它将从数据库中获取数据。



我正在使用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;





和aspx.cs页面:



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

推荐答案

您好,

您可以查看下面的

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; 
}





最好的问候

Muthuraja



Best Regards
Muthuraja


@Muthuraja非常感谢你的工作......

但是我的查询是在DAL我用它的方法访问它。

public List< tblmainaccount> GetMainAccountWithCode(字符串代码)

{//代码}



现在你提出的解决方案在代码背后隐藏了...

如何通过方法获得结果然后像你说的那样使用foreach在文本框中显示结果...



我需要什么得到结果列表然后使用foreach .. ??



问候

Wardah
@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


您好,



您能否将这些值存储在List< string>中或者一个Class变量,这样你就可以返回List< string>或者你的GetMainAccountWithCode()方法中的一个类。



请让我知道你的意见。



Best问候

Muthuraja
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


这篇关于在文本框中获取查询结果并下拉的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆