JavaScript操作服务器控件之Gridview控件
2021-05-15 18:27
阅读:644
YPE >
标签:sha command cells 获取 copyto wro ntc 第一个 void
1.JavaScript脚本如下:
2.aspx代码如下:
[c-sharp] view plain copy
print?
- "C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="TestWeb._Default" %>
- html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- "http://www.w3.org/1999/xhtml" >
- "server">
-
Untitled Page - function gridviewControl()
- {
- //获取GridView的客户端元素
- var table=document.getElementById("GridView1");
- //获取第5列(Test_Column,从0开始)的列标题
- var title = table.getElementsByTagName("th")[5].innerText;
- //循环访问第Test_Column中的控件
- for(var i=1;i
- {
- //获取第一个TextBox
- var txt1 = table.rows[i].cells[5].getElementsByTagName("INPUT")[0];
- //获取第二个TextBox
- var txt2 = table.rows[i].cells[5].getElementsByTagName("INPUT")[1];
- //获取 CheckBox
- var chkItem = table.rows[i].cells[5].getElementsByTagName("input")[2];
- //获取第一个DropDownList
- var ddlItem = table.rows[i].cells[5].getElementsByTagName("select")[0];
- //获取第二个DropDwonList
- var ddlItem2 = table.rows[i].cells[5].getElementsByTagName("select")[1];
- //测试结果
- alert("Title Name is " + title
- + ", /t/n 第一个TextBox的值 " + txt1.value
- + ", /t/n 第二个TextBox的值 " + txt2.value
- + ", /t/n CheckBox的选项值 " + (chkItem.checked ? ‘true‘ : ‘false‘)
- + ", /t/n 第一个DropDownList的选项值是: " + ddlItem.value
- + ", /t/n 第二个DropDownList的选项值是: " + ddlItem2.value);
- }
- }
- // -->
- "float:left;width:200px;">
"GridView1" runat="server" AutoGenerateColumns="False" - onrowcreated="GridView1_RowCreated">
"CH1" /> "CH2" /> "Column1" HeaderText=" Column1 " /> "Column2" HeaderText=" Column2 " /> "Column3" HeaderText=" Column3 " /> " Test_Column " > "gdvTxtValue" runat="server" Text=‘‘>
"gdvTxtItem" runat="server" Text=‘‘ BackColor="LightBlue">
"gdvchkValue" runat="server" Text=‘‘ Enabled=‘‘/>
"ddlItem" runat="server" > "True"> "I‘m No.11" Value="No.11"> "I‘m No.12" Value="No.12">
"ddlItem2" runat="server"> "True"> "I‘m No.21" Value="No.21"> "I‘m No.22" Value="No.22"> - "SqlDataSource1" runat="server"
- ConnectionString=""
- SelectCommand="SELECT * FROM [AP_TRANS]">
"SqlDataSource1"--%>
- "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?
- using System;
- using System.Collections;
- using System.Configuration;
- using System.Data;
- using System.Linq;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.HtmlControls;
- using System.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- using System.Xml.Linq;
- namespace TestWeb
- {
- public partial class _Default : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- //DataTable
- DataTable Record = new DataTable();
- Record.Columns.Add("Column1", typeof(int));
- Record.Columns.Add("Column2", typeof(string));
- Record.Columns.Add("Column3", typeof(string));
- Record.Columns.Add("txtData1", typeof(string));
- Record.Columns.Add("txtData2", typeof(string));
- Record.Columns.Add("chkData1", typeof(bool));
- Record.Columns.Add("chkEnableData1", typeof(bool));
- for (int i = 0; i
- {
- Record.Rows.Add();
- Record.Rows[i]["Column1"] = i + 1;
- Record.Rows[i]["Column2"] = "参照列1";
- Record.Rows[i]["Column3"] = "参照列2";
- Record.Rows[i]["txtData1"] = "Data of Box1-" + i.ToString();
- Record.Rows[i]["txtData2"] = "Data of Box2-" + i.ToString();
- Record.Rows[i]["chkData1"] = true;
- Record.Rows[i]["chkEnableData1"] = true;
- }
- GridView1.DataSource = Record;
- GridView1.DataBind();
- }
- protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
- {
- //e.Row.Cells[0].Visible = false;
- e.Row.Cells[0].Style.Add("display", "none");
- e.Row.Cells[1].Style.Add("display", "none");
- }
- protected void l2131l()
- {
- //string onclick =" ScriptName=ReturnThsSearch_0&"
- // + " tableId=&valueCount=0&Imode=0‘, null, ‘left=400, top=100, status=no, toolbar= no, location= no, menubar= no ,height=550,width=670‘);";
- //string onclick =" ScriptName=ReturnSearchVendor_0&"
- //+ " WS_CD=&Imode=1‘, null, ‘left=400, top=100, status=no, toolbar= no, location= no, menubar= no ,height=550,width=660‘);";
- }
- protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
- {
- this.Label1.Text = DropDownList1.Text;
- }
- protected void Button1_Click(object sender, EventArgs e)
- {
- this.Label1.Text = DropDownList1.SelectedItem.Text + "-" + DropDownList1.SelectedItem.Value;
- for (int i = 0; i this.DropDownList1.Items.Count; i++)
- {
- string ttt = this.DropDownList1.Items[0].Text + DropDownList1.Items[i].Value;
- }
- }
- }
- }
--------------------- 本文来自 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
文章来自:搜素材网的编程语言模块,转载请注明文章出处。
文章标题:JavaScript操作服务器控件之Gridview控件
文章链接:http://soscw.com/essay/85897.html
文章标题:JavaScript操作服务器控件之Gridview控件
文章链接:http://soscw.com/essay/85897.html
评论
亲,登录后才可以留言!