asp.net simple page Control Assignment Implementation Method _ Practical skills

Source: Internet
Author: User

The example in this article describes the method for assigning values to asp.net simple page controls. Share to everyone for your reference, specific as follows:

<summary>///Assignment Table name, control name, unique data to query///</summary> protected void Setevaluate (String tablename, String Upnam
    E, String Id) {ContentPlaceHolder cph = (ContentPlaceHolder) Page.Master.FindControl ("Cph_context"); UpdatePanel up = (UpdatePanel) cph.
    FindControl (Upname);
    DataTable dt = loapersonlogic.getpersontemp ("SELECT * from" + tablename + "where id= '" + ID + ""); for (int i = 0; i < dt. Columns.count; i++) {//Collection table header name DT. Columns[i]//Set value dt. Rows[0][i]. ToString () foreach (Control ctl. Controls[0]. Controls) {if ((CTL is TextBox) && ctl.id. Trim () = = dt. Columns[i]. ToString (). Trim ()) {(TextBox) CTL). Text = dt. Rows[0][i].
        ToString (); The IF ((CTL is DropDownList) && ctl.id. Trim () = = dt. Columns[i]. ToString (). Trim ()) {(DropDownList) CTL). Items.findbyvalue (dt. Rows[0][i]. ToString (). Trim ()).
        Selected = true; {}}}}///<summary>///generation SQL Modify SQL///</summary>///<param name= "tablename" > table name </param>///<param name= "Wyid" > Unique ID primary key </param>///<param name= "Upname" ></param>///<param name= "Id" > Modify id</param> Protected  String Createsql (String tablename, String Wyid, String upname, String Id) {string SQL = "Update" + tablename + "set
    ";
    ContentPlaceHolder cph = (ContentPlaceHolder) Page.Master.FindControl ("Cph_context"); UpdatePanel up = (UpdatePanel) cph.
    FindControl (Upname); foreach (Control ctl. Controls[0]. Controls) {if (CTL is TextBox) {sql = sql + ctl.id + = ' "+ (TextBox) CTL).
      Text + "',"; } if (CTL is DropDownList) {sql = SQL + ctl.id + "= '" + (DropDownList) CTL).
      SelectedItem.Value.Trim () + "',"; } if (SQL. IndexOf (', ') >-1) {sql = SQL. Substring (0, SQL.
    LENGTH-1) + "where" + Wyid + "= '" + Id + "'";
} return SQL;

 }

More interested readers of asp.net related content can view the site topics: "asp.net operation JSON tips summary", "asp.net string operation tips Summary", "ASP.net Operation XML Skills summary", "asp.net file Operation skills Summary", " asp.net Ajax Skills Summary topic and the "ASP.net cache operation skills Summary."

I hope this article will help you to ASP.net program design.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.