One of the joint operations of ASP. NET and JavaScript

Source: Internet
Author: User


In network development, it is often necessary to use ASP. NET and JavaScript For joint control. In this article, we will use the DataGrid for Data Binding and use Javascript to control the color of the row when the checkbox is selected.
First, create a DataGrid Control on the page and set its template.
<Asp: DataGrid id = "DataGrid1" runat = "server" AutoGenerateColumns = "False">
<Columns>
<Asp: TemplateColumn>
<ItemTemplate>
<Asp: CheckBox id = "checkbox1" Runat = "server"> </asp: CheckBox>
<Asp: Label runat = "server" Text = '<% # DataBinder. Eval (Container, "DataItem") %>'> </asp: Label>
</ItemTemplate>
</Asp: TemplateColumn>
</Columns>
</Asp: DataGrid>
Second, compile the JavaScript script function in <Script>
Function checkme (obj, tr ){
If (obj. checked)
Tr. style. backgroundColor = 'blue ';
Else
Tr. style. backgroundColor = '';
}
</Script>
Third, bind data to the DataGrid in the Page_Load event and associate it with the JavaScript script of the CheckBox.
Private void Page_Load (object sender, System. EventArgs e)
{
// Put user code to initialize the page here
If (! IsPostBack)
{
Databind ();
}
} Private void databind ()

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.