JavaScript操作服务器控件之Gridview控件

2021-05-15 18:27

阅读:633

YPE >

标签:sha   command   cells   获取   copyto   wro   ntc   第一个   void   

1.JavaScript脚本如下:

 

2.aspx代码如下:

 

[c-sharp] view plain copy
 
 
print?
  1. "C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="TestWeb._Default" %>  
  2.   
  3. html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  4.   
  5. "http://www.w3.org/1999/xhtml" >  
  6. "server">  
  7.     Untitled Page  
  8.     
  9.     function gridviewControl()  
  10.     {  
  11.         //获取GridView的客户端元素  
  12.         var table=document.getElementById("GridView1");  
  13.         //获取第5列(Test_Column,从0开始)的列标题  
  14.         var title = table.getElementsByTagName("th")[5].innerText;  
  15.         //循环访问第Test_Column中的控件  
  16.         for(var i=1;i
  17.         {   
  18.           //获取第一个TextBox  
  19.           var txt1 = table.rows[i].cells[5].getElementsByTagName("INPUT")[0];  
  20.           //获取第二个TextBox  
  21.           var txt2 = table.rows[i].cells[5].getElementsByTagName("INPUT")[1];  
  22.           //获取 CheckBox  
  23.           var chkItem = table.rows[i].cells[5].getElementsByTagName("input")[2];  
  24.           //获取第一个DropDownList  
  25.           var ddlItem = table.rows[i].cells[5].getElementsByTagName("select")[0];  
  26.           //获取第二个DropDwonList  
  27.           var ddlItem2 = table.rows[i].cells[5].getElementsByTagName("select")[1];            
  28.             
  29.           //测试结果  
  30.            alert("Title Name is " + title  
  31.                  + ",  /t/n  第一个TextBox的值 " + txt1.value   
  32.                  + ",  /t/n  第二个TextBox的值 " + txt2.value   
  33.                  + ",  /t/n  CheckBox的选项值 " + (chkItem.checked ? ‘true‘ : ‘false‘)   
  34.                  + ",  /t/n  第一个DropDownList的选项值是: " + ddlItem.value   
  35.                  + ",  /t/n  第二个DropDownList的选项值是: " + ddlItem2.value);  
  36.   }    
  37.          
  38.            }  
  39.       
  40. // -->  
  41.   
  42.   
  43.     
    "form1" runat="server">  
  44.     
    "float:left;width:200px;">  
  45.         "GridView1" runat="server" AutoGenerateColumns="False"   
  46.              onrowcreated="GridView1_RowCreated">  
  47.               
  48.                   
  49.                 "CH1" />  
  50.                 "CH2" />  
  51.                 "Column1" HeaderText="   Column1   "  />  
  52.                 "Column2" HeaderText="   Column2   " />  
  53.                 "Column3" HeaderText="   Column3   " />  
  54.                                   
  55.                 "   Test_Column    " >  
  56.                   
  57.                  "gdvTxtValue" runat="server" Text=‘‘>  
  58.                  
      
  59.                  "gdvTxtItem" runat="server" Text=‘‘ BackColor="LightBlue">  
  60.                  
      
  61.                  "gdvchkValue" runat="server" Text=‘‘ Enabled=‘‘/>  
  62.                  
                       
  63.                  "ddlItem" runat="server" >  
  64.                  "True">  
  65.                  "I‘m No.11" Value="No.11">  
  66.                  "I‘m No.12" Value="No.12">  
  67.                    
  68.                  
      
  69.                  "ddlItem2" runat="server">  
  70.                  "True">  
  71.                  "I‘m No.21" Value="No.21">  
  72.                  "I‘m No.22" Value="No.22">  
  73.                    
  74.                    
  75.                    
  76.                   
  77.               
  78.               
  79.           
  80.         "SqlDataSource1" runat="server"   
  81.             ConnectionString=""   
  82.             SelectCommand="SELECT * FROM [AP_TRANS]">  
  83.             
    "SqlDataSource1"--%>  
  84.             
      
  85.               
  86.     
  
  •     
    "position:absolute;left:450px;">  
  •     "DropDownList1" runat="server"  Visible="false" AutoPostBack="True"   
  •         Height="16px" onselectedindexchanged="DropDownList1_SelectedIndexChanged"   
  •         Width="149px">  
  •           
  •         "VAlue1">1  
  •         "value2">2  
  •         "value3">3  
  •           
  •       
  •     
  •     
  •     
      
  •     "button" id="btnTest" value="Test_Button" onclick="gridviewControl()" />  
  •     
  •   
  •       
  •   
  •   
  •  

     

    3.aspx.cs文件代码如下:

     

    [c-sharp] view plain copy
     
     
    print?
    1. using System;  
    2. using System.Collections;  
    3. using System.Configuration;  
    4. using System.Data;  
    5. using System.Linq;  
    6. using System.Web;  
    7. using System.Web.Security;  
    8. using System.Web.UI;  
    9. using System.Web.UI.HtmlControls;  
    10. using System.Web.UI.WebControls;  
    11. using System.Web.UI.WebControls.WebParts;  
    12. using System.Xml.Linq;  
    13.   
    14. namespace TestWeb  
    15. {  
    16.     public partial class _Default : System.Web.UI.Page  
    17.     {  
    18.         protected void Page_Load(object sender, EventArgs e)  
    19.         {  
    20.             //DataTable  
    21.             DataTable Record = new DataTable();  
    22.   
    23.             Record.Columns.Add("Column1", typeof(int));  
    24.             Record.Columns.Add("Column2", typeof(string));  
    25.             Record.Columns.Add("Column3", typeof(string));  
    26.             Record.Columns.Add("txtData1", typeof(string));  
    27.             Record.Columns.Add("txtData2", typeof(string));  
    28.             Record.Columns.Add("chkData1", typeof(bool));  
    29.             Record.Columns.Add("chkEnableData1", typeof(bool));  
    30.   
    31.             for (int i = 0; i 
    32.             {  
    33.                 Record.Rows.Add();  
    34.   
    35.                 Record.Rows[i]["Column1"] = i + 1;  
    36.                 Record.Rows[i]["Column2"] = "参照列1";  
    37.                 Record.Rows[i]["Column3"] = "参照列2";  
    38.                 Record.Rows[i]["txtData1"] = "Data of Box1-" + i.ToString();  
    39.                 Record.Rows[i]["txtData2"] = "Data of Box2-" + i.ToString();  
    40.                 Record.Rows[i]["chkData1"] = true;  
    41.                 Record.Rows[i]["chkEnableData1"] = true;  
    42.   
    43.             }  
    44.   
    45.             GridView1.DataSource = Record;  
    46.             GridView1.DataBind();  
    47.         }  
    48.   
    49.         protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)  
    50.         {  
    51.             //e.Row.Cells[0].Visible = false;  
    52.             e.Row.Cells[0].Style.Add("display", "none");  
    53.             e.Row.Cells[1].Style.Add("display", "none");  
    54.         }  
    55.         protected void l2131l()  
    56.         {  
    57.             //string onclick =" ScriptName=ReturnThsSearch_0&"  
    58.             //               + "  tableId=&valueCount=0&Imode=0‘, null, ‘left=400, top=100, status=no, toolbar= no, location= no, menubar= no ,height=550,width=670‘);";  
    59.             //string onclick =" ScriptName=ReturnSearchVendor_0&"  
    60.                            //+ "  WS_CD=&Imode=1‘,                    null, ‘left=400, top=100, status=no, toolbar= no, location= no, menubar= no ,height=550,width=660‘);";  
    61.         }  
    62.   
    63.         protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)  
    64.         {  
    65.             this.Label1.Text = DropDownList1.Text;  
    66.         }  
    67.   
    68.         protected void Button1_Click(object sender, EventArgs e)  
    69.         {  
    70.             this.Label1.Text =  DropDownList1.SelectedItem.Text + "-" + DropDownList1.SelectedItem.Value;  
    71.             for (int i = 0; i this.DropDownList1.Items.Count; i++)  
    72.             {  
    73.                 string ttt = this.DropDownList1.Items[0].Text + DropDownList1.Items[i].Value;  
    74.             }  
    75.         }  
    76.     }  
    77. }  

     

    --------------------- 本文来自 goforwarder 的CSDN 博客 ,全文地址请点击:https://blog.csdn.net/yd2005zxq/article/details/5613262?utm_source=copy 

    JavaScript操作服务器控件之Gridview控件

    标签:sha   command   cells   获取   copyto   wro   ntc   第一个   void   

    原文地址:https://www.cnblogs.com/asdyzh/p/9750653.html

    上一篇:刘志梅201771010115.《面向对象程序设计(java)》第六周学习总结

    下一篇:数组中重复出现的数字


    评论


    亲,登录后才可以留言!

    热门文章

    推荐文章

    最新文章

    置顶文章