您的位置:首页 > 其它

编辑记录时 绑定记录DATATABLE到页面控件

2012-06-08 12:23 246 查看
private void addrecord_Load(object sender, EventArgs e)

{

if (this.editid != 0)

{

rec r = new rec();

DataTable dt = r.queryByid(editid);

Bind(dt);

}

}

private void Bind(DataTable dt)

{

DataRow dr = dt.Rows[0];

for (int i = 0; i < dt.Columns.Count; i++)

{

DataColumn dc = dt.Columns[i];

bindTextboxValue(dc.ColumnName, dr[i].ToString());

}

//foreach (DataColumn dc in dr)

//{

// dc.ToString();

//}

// if (dt.Rows.Count == 0) return true;

}

private void bindTextboxValue(string name, string value)

{

foreach (Control con in this.Controls)

{

// if (!con.HasControls)

if (con is GroupBox)

{

foreach (Control con2 in con.Controls)

{

if (con2 is TextBox)

{

if (con2.Name.Equals(name))

con2.Text = value;

}

//

}

}

}

}

//bindTextboxValue
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐