zoukankan      html  css  js  c++  java
  • 编辑记录时 绑定记录DATATABLE到页面控件

     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

  • 相关阅读:
    php使用PHPMailer邮件类发送邮件
    apache一个IP一个端口对应多个域名
    网页宽度自动适应手机屏幕宽度的方法
    PHP抓取网页图片
    innodb存储引擎
    mysql存储引擎概述
    mysql事务
    mysql字符集
    mysql数据对象
    SQL-基础学习4--聚集函数:AVG(),COUNT(),MAX(),MIN(),SUM();聚集不同值:DISTINCT
  • 原文地址:https://www.cnblogs.com/attilax/p/15199994.html
Copyright © 2011-2022 走看看