Worth storing and assigning values for multiple text boxes

Source: Internet
Author: User

Question: there are multiple assessment results on one page, such as courtesy, expression skills, telephone control, listening skills, and emotional control. If you don't want to assess, there are multiple assessment criteria, such: such as rating, content, and dialog instances. If you create a new table, you need to store hundreds of fields on a page. This is obviously inappropriate, I solve the problem as follows:
1. Create a field based on the assessment criteria on the page. If there are 10 assessment criteria, a field is created.
2. the text box to be filled in according to the assessment standard should be named in a regular way, such as the name with the same prefix + number (I name it like this)
3. cyclically retrieve the value in the background based on the corresponding name, add a separator, and finally store it in the corresponding field.
The page area is shown as follows:
 


 
Main background processing methods:
When inserting data into a database:
// Retrieve the values in all dialog Instance columns and splice them into strings to assign values to Instance, Score, and Content.
StringBuilder Instance = new StringBuilder ();
StringBuilder Score = new StringBuilder ();
StringBuilder TutorContent = new StringBuilder ();

For (int I = 1; I <= 52; I ++)
{
If (Page. FindControl ("tbx_Instance" + I). GetType () = typeof (TextBox ))
{
Instance. Append (Page. FindControl ("tbx_Instance" + I) as TextBox). Text + "#&");
}
If (Page. FindControl ("tbx_content" + I). GetType () = typeof (TextBox ))
{
TutorContent. Append (Page. FindControl ("tbx_content" + I) as TextBox). Text + "#&");
}
If (Page. FindControl ("ddl_S" + I). GetType () = typeof (DropDownList ))
{
Score. Append (Page. FindControl ("ddl_S" + I) as DropDownList). SelectedValue + "#&");
}

Retrieve from the database and assign values to the corresponding text:
// Assign a value to the dialog instance text box
String intance = dtCS. Rows [0] ["Example"]. ToString ();
String [] sInstance = Regex. Split (intance, "# &", RegexOptions. IgnoreCase );
For (int I = 1; I <sInstance. Length; I ++)
{
(Page. FindControl ("tbx_Instance" + I) as TextBox). Text = sInstance [I-1];
}
// Assign a value to the tutoring content text box
String content = dtCS. Rows [0] ["TutorContent"]. ToString ();
String [] sContent = Regex. Split (content, "# &", RegexOptions. IgnoreCase );
For (int I = 1; I <sContent. Length; I ++)
{
(Page. FindControl ("tbx_content" + I) as TextBox). Text = sContent [I-1];
}
// Assign a score
String Score = dtCS. Rows [0] ["Score"]. ToString ();
String [] sScore = Regex. Split (Score, "# &", RegexOptions. IgnoreCase );
For (int I = 1; I <sScore. Length; I ++)
{
(Page. FindControl ("ddl_S" + I) as DropDownList). SelectedValue = sScore [I-1];
}
 
 

From wggKingJust

Related Article

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.