问题描述
大家好,
我的问题似乎很简单,但很难找到答案.
如何将DataRepeater的控件分配给数据库表columnID's?
我有一个数据转发器,上面有3个控件,Lable和2个文本框.如何将每个控件分配给数据表中的列
Hi All,
My question seems simple but am having hard time finding the Answer.
How can I assign controls of the DataRepeater to database table columnID''s?
I have a data repeater with 3 controls on it, Lable, and 2 Textboxs. How can i assign each control to to the column in the datatable
SqlCommand cmd = new SqlCommand("Select * from surveyQuestions", con);
SqlDataAdapter adapt = new SqlDataAdapter(cmd);
DataTable questions = new DataTable();
adapt.Fill(questions);
dataRepeater1.DataSource = questions;
???
我正在使用Windows而不是Web.
请帮帮我.
在此先感谢.
???
Am Using Windows not Web.
Please help me.
Thanks in Advance.
推荐答案
TextBox1.DataBindings.Add("Text", questions, "Column1");
DataRepeater.DataSource=questions;
文本"是您要绑定的控件的属性-您可以绑定到其他属性,例如标签",可见"等.希望您能理解.
这是另一个复选框绑定示例
"Text" is the property of the control you''re binding to - you can bind to other properties like "Tag", "Visible" etc. Hope you get the idea.
Here''s another checkbox binding example
CheckBox1.DataBindings.Add("Checked",questions","Column2");
添加中继器和其中的一个文本框&运行此代码以测试是否需要
Add a repeater & a textbox within it & run this code to test if you want
DataTable dt = new DataTable()
dt.Columns.Add("c1");
dt.Rows.Add("1");
dt.Rows.Add("2");
dt.Rows.Add("3");
dt.Rows.Add("4");
dt.Rows.Add("5");
TextBox1.DataBindings.Add("Text", dt, "c1");
DataRepeater1.DataSource = dt;
这篇关于Windows窗体中的DataRepeater控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!