当前位置:编程学习 > C#/ASP.NET >>

在继承中用到datagridview、bindingsource、textbox 结合问题

由于刚刚涉入C#,所以一些基本的问题还不是很清楚,发贴向论坛上的高手们请教请教: 

编教务管理系统时,遇到在继承的环境中同时把datagridview、bindingsource、textbox 都绑定到同一个数据源,可是我编班级信息维护时,运行没问题,可最后textbox 并没有显示内容,貌似没有绑定上去。
     sing System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using SIMS.classdb;
using System.Data.SqlClient;

namespace SIMS
{
    public partial class ClassInfo : SIMS.frmBase
    {
        public ClassInfo()
        {
            InitializeComponent();
        }
        public override void Prepare ()
        {
            this.Text = "班级信息维护";
            this.label1.Text = "班级编号";
            this.label2.Text = "年级";
            this.label3.Text = "班级名称";
        }

        public override void SetDataGrid()
        {
             
            BindingSource bs = new BindingSource();
            bs.DataSource = getcds().Tables[0];
            bindingNavigator1.BindingSource = bs;
            dataGridView1.DataSource = bs;
        }

        public override void SearchResult()
        {
            BindingSource bs = new BindingSource();
            bs.DataSource = getcds1().Tables[0];
            bindingNavigator1.BindingSource = bs;
            dataGridView1.DataSource = bs;
        }

        BindingSource myBindingSource;
        DataSet myDataSet = new DataSet();
        SqlDataAdapter myAdapter;
        SqlCommandBuilder myCommandBuilder;
        public void BindingControl()
        {
            textBox4.DataBindings.Add("Text",myBindingSource ,"班级编号");
            textBox5.DataBindings.Add("Text", myBindingSource, "年级");
            textBox6.DataBindings.Add("Text", myBindingSource, "班级名称");
            textBox7.DataBindings.Add("Text", myBindingSource, "班级简称");
            textBox8.DataBindings.Add("Text", myBindingSource, "人数");
            textBox9.DataBindings.Add("Text", myBindingSource, "班主任");
        }

        private void ClassInfo_Load(object sender, EventArgs e)
        {
            DBConn app=new DBConn ();
            SqlConnection conn=app .getConnection ();
            Prepare();
            SetDataGrid();
            string sql = "select * from 班级信息表";
            myAdapter = new SqlDataAdapter(sql,conn);
            myAdapter.Fill(myDataSet ,"class");
            myCommandBuilder = new SqlCommandBuilder(myAdapter);
            BindingControl();
        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            SearchResult();
        }

        private void bindingNavigatorAddNewItem_Click(object sender, EventArgs e)
        {
            myBindingSource.EndEdit();
            myAdapter.Update(myDataSet .Tables ["class"]);
                    } --------------------编程问答-------------------- up --------------------编程问答-------------------- 来学习的,关注中
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,