Algorithm (data cannot be written across rows)

Source: Internet
Author: User

Requirement: if there are four columns in sequence, when the second column is empty, the third column cannot have values, and so on.

Front-end:

  1. <% @ Page Language = "C #" autoeventwireup = "true" codefile = "checknull. aspx. cs" inherits = "test_checknull" %>
  2. <! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <HTML xmlns = "http://www.w3.org/1999/xhtml">
  4. <Head runat = "server">
  5. <Title> not added before, not later. </Title>
  6. <SCRIPT type = "text/JavaScript">
  7. // Function. It is not written before and cannot be added later.
  8. // The expected improvement is that an array can be input and determined based on the array length.
  9. Function fnotnull (){
  10. // Boolean B = true; // The boolean type fails.
  11. VaR B = 0; // 0 indicates that verification is passed, and 1 indicates that verification is not passed.
  12. If (document. getelementbyid ('tb1 '). value = "")
  13. B = 1;
  14. For (I = 1; I <5; I ++) {// set the ID range.
  15. VaR T = 'tb' + I;
  16. VaR TXT = Document. getelementbyid (t );
  17. If (txt. value = "") // if it is null, the system checks whether there is a value next to it.
  18. For (j = I + 1; j <5; j ++) {// you can specify the ID range. This should start with I + 1.
  19. VaR x = 'tb' + J;
  20. VaR TT = Document. getelementbyid (X );
  21. If (TT. value! = "")
  22. B = 1;
  23. }
  24. }
  25. Return B;
  26. }
  27. Function fcheck (){
  28. If (fnotnull () = "0 ")
  29. Alert ('verified ');
  30. Else
  31. Alert ('the first column cannot be blank and cannot be added across rows! ');
  32. }
  33. </SCRIPT>
  34. </Head>
  35. <Body>
  36. <Form ID = "form1" runat = "server">
  37. <Div>
  38. <Asp: textbox id = "tb1" runat = "server"> </ASP: textbox>
  39. <Asp: textbox id = "tb2" runat = "server"> </ASP: textbox>
  40. <Asp: textbox id = "int32" runat = "server"> </ASP: textbox>
  41. <Asp: textbox id = "tb4" runat = "server"> </ASP: textbox>
  42. <Input type = "button" value = "JS Verification" onclick = "fcheck ();"/>
  43. <Asp: button id = "btncheck" runat = "server" text = "C # verify" onclick = "btncheck_click"/>
  44. </Div>
  45. </Form>
  46. </Body>
  47. </Html>

Background:

  1. Using system;
  2. Using system. Data;
  3. Using system. configuration;
  4. Using system. collections;
  5. Using system. Web;
  6. Using system. Web. Security;
  7. Using system. Web. UI;
  8. Using system. Web. UI. webcontrols;
  9. Using system. Web. UI. webcontrols. webparts;
  10. Using system. Web. UI. htmlcontrols;
  11. Public partial class test_checknull: system. Web. UI. Page
  12. {
  13. Protected void page_load (Object sender, eventargs E)
  14. {
  15. }
  16. Protected void btncheck_click (Object sender, eventargs E)
  17. {
  18. If (checknull ())
  19. Response. Write ("verified! ");
  20. Else
  21. Response. Write ("the first column cannot be blank and cannot be added to the second row! ");
  22. }
  23. /// <Summary>
  24. /// Determine whether data is written in the same row.
  25. /// </Summary>
  26. /// <Returns> </returns>
  27. Private bool checknull ()
  28. {
  29. Bool B = true;
  30. Arraylist arr = new arraylist ();
  31. Arr. Add (this. tb1.text. Trim ());
  32. Arr. Add (this. tb2.text. Trim ());
  33. Arr. Add (this. tb3.text. Trim ());
  34. Arr. Add (this. tb4.text. Trim ());
  35. For (INT I = 0; I <arr. Count; I ++)
  36. {
  37. If (ARR [I]. tostring () = "") // If the column is empty, check whether the column is followed by a value.
  38. For (Int J = I + 1; j <arr. Count; j ++)
  39. {
  40. If (ARR [J]. tostring ()! = "")
  41. B = false;
  42. }
  43. }
  44. Return B;
  45. }
  46. }

End

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.