Recyclically assign a value to textbox !! Asp.net

Source: Internet
Author: User

<Div id = "textboxs" runat = "server">

<Asp: textbox id = "COM1" runat = "server"> </ASP: textbox>

<Asp: textbox id = "com2" runat = "server"> </ASP: textbox>

<Asp: textbox id = "com2" runat = "server"> </ASP: textbox>

</Div>

Assume that the storage method of the comname field in the database is: "image, book, tutorial" with a bean number in the middle

String [] comarray = Dr ["comname"]. tostring (). Split (',');

Foreach (INT I = 0; I <comarray. lenth; I ++)

{

(Textbox) This. textboxs. findcontrol ("com" + (I + 1). tostring (). Text = comarray [I]. tostring ();

}

Okay, now it's done,

Note:When using findcontrol, you must add a container outside the closest to the search object. If you directly use this. findcontrol or page. findcontrol, it will often appear.Object not set to instanceSo it is best to add a container, then the DIV added here is a container, in order to make findcontrol find the name COM1, com2 In the DIV whose ID is "textboxs, textbox of com3;

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.