Access the bound field of gridview by JavaScript)

Source: Internet
Author: User

 

 

< Form ID = "Form1" Runat = "Server" >
  < ASP: gridview ID = "Gridview1" Autogeneratecolumns = "False" Showheader = "True" Runat = "Server" Onrowdatabound = "Gridview1_rowdatabound" >
< Columns >
< ASP: boundfield Headertext = "Name" Datafield = "Name" Readonly = "True"   />
< ASP: boundfield Headertext = "Amount" Datafield = "Amount" Readonly = "True"   />
< ASP: templatefield Headertext = "Checkbox" >
< Itemtemplate >
< ASP: checkbox ID = "Gridcheckbox" Runat = "Server"   />
</ Itemtemplate >
</ ASP: templatefield >
< ASP: templatefield Headertext = "Textbox" >
< Itemtemplate >
< ASP: textbox ID = "Gridtextbox" Runat = "Server" > </ ASP: textbox >
</ Itemtemplate >
</ ASP: templatefield >
</ Columns >
  </ ASP: gridview >
</ Form >

 

 

 

< Script Type = " Text/JavaScript " >
<! --
Function Gridcheckboxonclick (elementref, textboxid, amountvalue)
{
Document. getelementbyid (textboxid). Value = (Elementref. Checked) ? Amountvalue: '' ;
}
// -->
< / SCRIPT>

 

 

 

Protected   Void Gridview1_rowdatabound ( Object Sender, gridviewroweventargs E)
{
  If (E. Row. rowtype = Datacontrolrowtype. datarow)
{
// The name is in bound column #0
// String namevalue = E. Row. cells [0]. text;

//The amount is in bound column #1
StringAmountvalue=E. Row. cells [1]. Text;

// checkbox with an ID of" gridcheckbox "is in column #2 of the grid
checkbox gridcheckbox = (checkbox) E. row. cells [ 2 ]. findcontrol ( " gridcheckbox " );

//Textbox with an ID of "gridtextbox" is in column #3 of the grid
Textbox gridtextbox=(Textbox) E. Row. cells [3]. Findcontrol ("Gridtextbox");

If (Gridcheckbox ! =   Null ) && (Gridtextbox ! =   Null ))
{
Gridcheckbox. Attributes. Add ( " Onclick " , String . Format ( " Gridcheckboxonclick (this, '{0}', '{1 }'); " , Gridtextbox. clientid, amountvalue ));
}
}
}

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.