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.