Control HTML page tag attributes in background code

Source: Internet
Author: User

A tips used in your work. For example, if you want to control the width and height of a <div> tag on the page, the data read by the database will automatically change.

On the page, add the ID and runat attributes to the <div> label,
<Div id = "div1" runat = "server">
In the backgroundCodeDeclare Variables
Protected system. Web. UI. htmlcontrols. htmlgenericcontrol div1;
Then you can play it as you like. For example, in a project, it is generally used as follows:
Private void binddetail ()
{
This. dgdetail. datasource = This. dsdetail. Tables [0];
This. dgdetail. databind ();
This. div1.style ["height"] = convert. tostring (this. dgdetail. Items. Count + 2) * 25-5 );
}
Use div1.style [] to set various attributes of the page tag div1.

Another common feature is the <tr> <TD> mark, which usually displays different data based on a specific status value.
On the page, add the ID and runat attributes:
<Tr Height = "18" id = "trbank" runat = "server">
<Tr Height = "18" id = "trmail;" runat = "server">
Declare variables in the background code
Protected system. Web. UI. htmlcontrols. htmltablerow trbank;
Protected system. Web. UI. htmlcontrols. htmltablerow trmail;

If (.....)
{// Display trbank data to hide trmail's
This. trbank. Style ["display"] = "";
This. trmail1.style ["display"] = "NONE ";
}
Else
{// Display trmail's
This. trbank. Style ["display"] = "NONE ";
This. trmail1.style ["display"] = "";
}

TIPS: page processing.
The variable declaration corresponding to an HTML page is usually completed after
Protected system. Web. UI. htmlcontrols.
In the pop-up automatic selection.

 

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.