Windows窗体中的DataRepeater控件 [英] DataRepeater Control in windows form

查看:90
本文介绍了Windows窗体中的DataRepeater控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我的问题似乎很简单,但很难找到答案.
如何将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.

推荐答案

http://blogs.msdn.com/b/vsdata/archive/2009/08/12/datarepeater-control-for-windows -forms.aspx

希望此链接对您有帮助.
http://blogs.msdn.com/b/vsdata/archive/2009/08/12/datarepeater-control-for-windows-forms.aspx

Hope this link helps you.


Msdn文档仅告诉您如何使用设计器进行数据绑定.几年前,我也很难学习这种简单的方法:)
您正在手动加载数据和绑定-这是一个手动绑定到放置在转发器内的文本框的示例
假设TextBox的名称是TextBox1,DataTable的名称是问题,Repeater的名称是DataRepeater1&表中的列,例如"Column1","Column2"等
Msdn docs only tell you how to databind using the designer. I too had a bit of a hard time learning this simple thing a few years earlier :)
You''re manually loading data & binding - here''s an example of manually binding to a textbox placed within a repeater
Assuming TextBox name is TextBox1, DataTable''s name is questions, Repeater''s name is DataRepeater1 & columns in your table like "Column1", "Column2" etc
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控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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