打印本文 打印本文 关闭窗口 关闭窗口
【翻译】在DataGrids和DropDownLists中使用ADO
作者:武汉SEO闵涛  文章来源:敏韬网  点击数3386  更新时间:2009/4/23 10:43:12  文章录入:mintao  责任编辑:mintao
    {

      SqlConnection myConnection = new SqlConnection(strConnectSQL);

      SqlCommand myCommand = new SqlCommand( SQLstring, myConnection );

      myConnection.Open();

 

      Dlist.DataSource = myCommand.ExecuteReader();

      Dlist.DataTextField = TextField;

      Dlist.DataValueField = ValueField;

      Dlist.DataBind();

 

      myConnection.Close();

    }

 

#region Web Form Designer generated code

    override protected void OnInit(EventArgs e)

    {

      //

      // CODEGEN: This call is required by the ASP.NET Web Form Designer.

      //

      InitializeComponent();

      base.OnInit(e);

    }

 

/// <summary>

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

/// </summary>

    private void InitializeComponent()

    {

      this.Load += new System.EventHandler(this.Page_Load);

    }

#endregion
  }

}

有趣的地方

这样做的好处之一就是你可以在ASP.NET中指定 web 控件作为函数的输入参数。这确实改变了我的编码习惯,我现在正在开发更多的一般性的可重用代码。

为什么使用这些代码

这非常简单。一旦你要为一个特定的控件编码,你就不必再重新写一次了。你可以一次又一次地使用相同的代码。

历史

200411 V1.1

上一页  [1] [2] [3] [4] 

打印本文 打印本文 关闭窗口 关闭窗口