zoukankan      html  css  js  c++  java
  • Js获取Gridview中模板列控件ID,获取控件生成的HTML中的ID Fred

    在Gridview的RowDataBound事件写如下代码:
    if (e.Row.RowState == DataControlRowState.Edit || (e.Row.RowState == (DataControlRowState.Edit || DataControlRowState.Alternate)))
            {
    //当该列处于编辑状态时单击第四个单元格里的控件时,调用js里的show方法并将控件id传进show方法
                ((TextBox)(e.Row.Cells[4].Controls[1])).Attributes["onclick "= 

    "show( '" + ((TextBox)(e.Row.Cells[4].Controls[1])).ClientID + " ');";
            }在html写js方法用来处理传过来的控件idfunction show(id)
            {
                
    //alert(id);
                
    //取出来的控件id中的$被转成了下划线(GridView1$ctl04$txt_number)转成 
               
    //(GridView1_ctl04_txt_number)
                
    //我们定义一个数组对传进的的控件id进行分割,然后再将字符合并
                
    //如果您定义的控件id中没有下划线(_)可以用正则来替换{id.replace(/_/g,"&")}
                
    //alert(id.replace(/_/g,"&"));             
     
    //var id1=new Array();
                
    //id1=id.split("_")
                
    //var controlName=id1[0]+"&"+id1[1]+"&"+"txt_code";
                
    //alert(controlName);    alert(id); }
    Sample:
    protected void gridviewProduct_RowDataBound(object sender, GridViewRowEventArgs e)        {            e.Row.Cells[0].Visible = false;                       if (e.Row.RowType == DataControlRowType.DataRow)            {                ((TextBox)(e.Row.Cells[3].FindControl("txt首月"))).Attributes["onchange"= "show                 ( '" + ((TextBox)(e.Row.Cells[3].FindControl("txt首月"))).ClientID + " ','"                   + ((TextBox)(e.Row.Cells[3].FindControl("txt次月"))).ClientID + " ','"                   + ((TextBox)(e.Row.Cells[3].FindControl("txt末月"))).ClientID + " ');";            }                    }
    页面代码:
    function show(id1,id2,id3)        {           alert(id1+id2+id3);        }

  • 相关阅读:
    通过电脑chrome调试手机真机打开的微信H5页面,调试电脑微信H5页面
    关于神策埋点数据采集
    jmeter控制仅一次登录的三种方案
    win10下mysql8.0.19解压版的安装教程
    mysql中的case when then 的用法
    python+openpyxl的excel的相关读写
    使用Gitlab-CI 实现NetCore项目Docker化并部署到阿里云K8S
    NetCore 中间件获取请求报文和返回报文
    WebApi 通过拦截器设置特定的返回格式
    NetCore AutoMapper的封装
  • 原文地址:https://www.cnblogs.com/Fred_Xu/p/1564687.html
Copyright © 2011-2022 走看看