gridview 数据绑定问题?
在 gridview 我总是在它的属性窗口加绑定列(BoundField)
在绑定列的(DataFile)属性添加要绑定的数据库字段名。
但这种方法不灵活 ,想在后台写,但没找到怎呢帮,也不想再html 中绑!
GridView grid= new GridView;
grid.....= "字段名 ";
类似这种方法!!
------解决方案--------------------private void frmRule_Load(object sender, EventArgs e)
{
this.FillData();
this.dvMaster = this.dtMaster.DefaultView;
this.dataGridView1.DataSource = bindMaster;
this.dataGridView2.DataSource = bindDetail;
this.SetDataBind();
this.setReadOnlyOnOff(true);
}
private void FillData()
{
string sql = "select * from sysrulegroup ";
this.dtMaster.Clear();
this.dtMaster = dataAccess.ExecuteSql(sql);
this.bindMaster.DataSource = this.dtMaster;
}
private void SetDataBind()
{
this.dataGridView1.Columns[ "ID_RULEGROUP "].Visible = false;
this.dataGridView1.Columns[ "no_RULEGROUP "].HeaderText = "角色群编号 ";
this.dataGridView1.Columns[ "nm_RULEGROUP "].HeaderText = "名称 ";
this.txtRuleGruopId.DataBindings.Add( "Text ", bindMaster, "id_rulegroup ");
this.txtRuleGroupNo.DataBindings.Add( "Text ", bindMaster, "no_rulegroup ");
this.txtRuleGroupName.DataBindings.Add( "Text ", bindMaster, "nm_rulegroup ");
}
=====c/s结构的,b/s的应该差不多吧