日期:2014-05-18  浏览次数:20453 次

textbox有DataBindings属性么?
this.TextBox1.DataBindings.Add( "Text ",   ds,   "SiteName ");
怎么就不行呢?并不包含“DataBindings”的定义
即可给分

------解决方案--------------------
要在组件里才可以的比如gridview
------解决方案--------------------
textBox1.DataBindings.Add(new Binding( "text ", ds, "SiteName "));
------解决方案--------------------
不行找我
------解决方案--------------------
下面的这段代码肯定能执行:
public DataSet getConnected()
{
SqlConnection conn = new SqlConnection( "server=localhost;database=testdb;uid=sa;password=123 ");
SqlDataAdapter adp = new SqlDataAdapter( "SELECT * FROM TestTable ", conn);
DataSet ds = new DataSet();
adp.SelectCommand.ExecuteNonQuery();
adp.Fill(ds, "testTable ");
return ds;
}

BindingManagerBase bm;

private void button1_Click(object sender, EventArgs e)
{
DataSet ds = getConnected();
bm = this.BindingContext[ds, "testTable "];
textBox1.DataBindings.Add(new Binding( "text ", ds, "testTable.testcolumn1 "));
textBox2.DataBindings.Add(new Binding( "text ", ds, "testTable.testcolumn2 "));
}
导航Button代码:
private void button2_Click(object sender, EventArgs e)
{
bm.Position -= 1;
}
private void button3_Click(object sender, EventArgs e)
{
bm.Position += 1;
}
------解决方案--------------------
Web中不能使用
------解决方案--------------------


public DataSet getConnected()
{
SqlConnection conn = new SqlConnection( "server=localhost;database=testdb;uid=sa;password=123 ");
SqlDataAdapter adp = new SqlDataAdapter( "SELECT * FROM TestTable ", conn);
DataSet ds = new DataSet();
adp.SelectCommand.ExecuteNonQuery();
adp.Fill(ds, "testTable ");
return ds;
}

BindingManagerBase bm;

private void button1_Click(object sender, EventArgs e)
{
DataSet ds = getConnected();
bm = this.BindingContext[ds, "testTable "];
textBox1.DataBindings.Add(new Binding( "text ", ds, "testTable.testcolumn1 "));
textBox2.DataBindings.Add(new Binding( "text ", ds, "testTable.testcolumn2 "));
}
导航Button代码:
private void button2_Click(object sender, EventArgs e)
{
bm.Position -= 1;
}
private void button3_Click(object sender, EventArgs e)
{
bm.Position += 1;
}