使用LINQ2SQL填充文本框 [英] Populating textboxes using LINQ2SQL
问题描述
在我的Web表单中,我需要通过LINQ2SQL查询来填充文本框和一个单选列表.到目前为止,我已对该查询进行编码以获取要填充到数据库中的特定记录.
In my web forms, I have text boxes and one radiolist which I need to populate through a LINQ2SQL query. So far I coded this query to fetch particular records which is going to be populated into the DB.
using (dbTestDataContext db = new dbTestDataContext())
{
var query = from r in db.Table1
where r.Code == getCode
select new
{
//Account Info
r.Name,
r.Num,
r.AcctNum,
r.CorpAcct, //Bool
};
};
现在我知道该查询将要获取的记录将只有1个唯一记录.我想在这些文本框中显示记录,然后选择该单选按钮:
Now I know that the record which this query is going to be fetching is gonna be only 1 unique record. I want to show the record in these textboxes and select that radio button:
tbName
tbNum
tbAcctNum
rbtnCorpAcct
tbName
tbNum
tbAcctNum
rbtnCorpAcct
我应该怎么做?预先谢谢你!
How should I do this? Thank you in advance!
推荐答案
与其他人一样,都添加了单选按钮:
Same as others have answered with addition of radio button:
tbName.Text = query.Name;
tbNum.Text = query.Num;
tbAcctNum.Text = query.AcctNum;
if(query.CorpAcct)
rbtn.SelectedValue = "Yes"; \\Where "Yes" is one of the radio button values
else
rbtn.SelectedValue = "No";
\\Could also use SelectedIndex, rbtn.SelectedIndex = 0 or 1
这篇关于使用LINQ2SQL填充文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!