想手动在页面取消和显示一个列,这个列是GridView的模板列,要怎么样处理才可以呢,谢谢
解决方案 »
- 单点登录 重来没有搞过。高手帮帮忙
- 去空格函数
- 为什么每次发布网站时都提示:某文件已在源编辑器之外被修改?
- 分布式缓存系统Memcached,请问有谁使用过吗,可不可以介绍一下
- 高分急求一.NET——1.1在线编辑器控件,要求
- 数据存储的算法 --------------求救
- 在vs2005中,button 有ImageURL属性吗?
- input - file控件 上传文件时 上传的路径本地调试时是用的绝对路径 要是上传到服务器是不是得该
- 怎样保留字符串中的空格
- 关于从数据库中读取“Image”,并显示在页面中的问题?----------------------------
- 如何读取的xml
- 大家好小弟弄了个论坛好希望大家帮帮我可以吗??【给分了】
遍历每一行(<tr>),将相应的cell(<td>)style 的display设为none.
var table = document.getElementById("table");
var trs = table.getElementsByTagName("tr");
for(var i = 0;i<trs.length;i++){
var tds = trs.getElementsByTagName("td");
for(var j = 0 ;j<tds.length;j++){
if(j = 你要删除的列){
trs.removeChilds(tds[i]);
}
}
}}
你这个思路我想过
但无论tr还是td都没有id或Name哦,具体GridView生成的代码如下,我想在打印时屏蔽最后一列否决原因
<tr class="GridHeaderStyle" style="border-width:1px;border-style:solid;font-weight:bold;">
<th scope="col" style="border-color:Black;border-width:1px;border-style:Solid;">序号</th><th scope="col">产品ID</th>
<th scope="col">产品名称</th>
<th scope="col">否决原因</th>
</tr>
<tr align="center" style="background-color:#EFF3FB;">
<td align="center" style="border-color:Black;border-width:1px;border-style:Solid;">
1 </td>
<td>1441</td>
<td>胶囊</td>
<td><input name="GridView1$ctl02$txtRejectReason" type="text" maxlength="100" id="GridView1_ctl02_txtRejectReason" /></td>
</tr>
wuxing2006(金宝) :
你这个思路我想过
---------------
其实 wuxing2006(金宝) 已经给我们很大到的提示了, 2。
这里我实现了一个 Demo, 同时实现了隐藏 列 和 行<%@ Page Language="C#" %>
<%@ Import Namespace="System.Data" %><%--http://community.csdn.net/Expert/TopicView3.asp?id=5582620--%><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server">
void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack) {
LoadProductData();
}
}
void LoadProductData()
{
DataTable dt = CreateProductTable();
GridView1.DataSource = dt;
GridView1.DataBind();
} #region sample data static DataTable CreateProductTable()
{
DataTable tbl = new DataTable("Products"); tbl.Columns.Add("ProductID", typeof(int));
tbl.Columns.Add("ProductName", typeof(string));
tbl.Columns.Add("CategoryID", typeof(int));
DataRow row = tbl.NewRow();
row[0] = 1;
row[1] = "Chai";
row[2] = 1;
tbl.Rows.Add(row); row = tbl.NewRow();
row[0] = 2;
row[1] = "Chang";
row[2] = 1;
tbl.Rows.Add(row); row = tbl.NewRow();
row[0] = 3;
row[1] = "Aniseed Syrup";
row[2] = 2;
tbl.Rows.Add(row); row = tbl.NewRow();
row[0] = 4;
row[1] = "Chef Anton's Cajun Seasoning";
row[2] = 2;
tbl.Rows.Add(row); row = tbl.NewRow();
row[0] = 5;
row[1] = "Chef Anton's Gumbo Mix";
row[2] = 2;
tbl.Rows.Add(row); row = tbl.NewRow();
row[0] = 47;
row[1] = "Zaanse koeken";
row[2] = 3;
tbl.Rows.Add(row); row = tbl.NewRow();
row[0] = 48;
row[1] = "Chocolade";
row[2] = 3;
tbl.Rows.Add(row); row = tbl.NewRow();
row[0] = 49;
row[1] = "Maxilaku";
row[2] = 3;
tbl.Rows.Add(row); return tbl;
} #endregion</script><html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Untitled Page</title>
<script type="text/javascript">
function showGridViewColumn(grdId, colIndex, show)
{
//debugger;
colIndex = (colIndex == null) ? 0 : parseInt(colIndex);
show = (show == null) ? false : new Boolean(show).valueOf();
// 得到 GridView 呈现的 table
var grdTbl = document.getElementById(grdId);
if(!grdTbl) return alert("指定的 GridView 不存在。");
// 得到 table 中的所有 tr
var trArr = grdTbl.getElementsByTagName("tr");
for(var i = 0; i < trArr.length; i++) {
// 得到每行 中的所有 td
var tdArr = trArr[i].getElementsByTagName("td");
// 尝试 th 表头
if(tdArr.length == 0) tdArr = trArr[i].getElementsByTagName("th");
// 防止越界,只判断一次,这里假设不存在合并单元格
if(i == 0 && colIndex >= tdArr.length) break;
// 显示 或者 隐藏
tdArr[colIndex].style.display = show ? "" : "none";
}
}
function showGridViewRow(grdId, rowIndex, show)
{
rowIndex = (rowIndex == null) ? 0 : parseInt(rowIndex);
show = (show == null) ? false : new Boolean(show).valueOf();
// 得到 GridView 呈现的 table
var grdTbl = document.getElementById(grdId);
if(!grdTbl) return alert("指定的 GridView 不存在。");
// 得到 table 中的所有 tr
var trArr = grdTbl.getElementsByTagName("tr");
// 防止越界,只判断一次,这里假设不存在合并单元格
if(rowIndex >= trArr.length) return;
// 显示 或者 隐藏
trArr[rowIndex].style.display = show ? "" : "none";
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
选择第<select id="sltColumns">
<option value="0">1</option>
<option value="1">2</option>
<option value="2">3</option>
</select>列
<!-- 这里请根据变通需要调用函数 showGridViewColumn('GridView1', document.getElementById('sltColumns').value, true) -->
<input type="button" onclick="showGridViewColumn('GridView1', document.getElementById('sltColumns').value, true)" value="show" />
<input type="button" onclick="showGridViewColumn('GridView1', document.getElementById('sltColumns').value, false)" value="hide" />
<br />
选择第<select id="sltRows">
<option value="0">1</option>
<option value="1">2</option>
<option value="2">3</option>
<option value="3">4</option>
<option value="4">5</option>
</select>行
<input type="button" onclick="showGridViewRow('GridView1', document.getElementById('sltRows').value, true)" value="show" />
<input type="button" onclick="showGridViewRow('GridView1', document.getElementById('sltRows').value, false)" value="hide" />
<asp:GridView ID="GridView1" runat="server" >
</asp:GridView>
</div>
</form>
</body>
</html>Hope helpful!
document.getElementById("GridView1").rows[2].style.display = "none";//隐藏第三列
for(var i = 0; i < document.getElementById("GridView1").rows.length; i ++)
document.getElementById("GridView1").rows[i].cells[2].style.display = "none";
table.rows(5).cells(0)
改为:
table.rows[5].cells[0]
{
e.Item.Cells[i].Style.Add("display","none");
}
包括像treeview这样的控件
document.getElementById("GridView1").rows[2].style.display = "none";后台隐藏
GridView.Columns[2].Visable=false;
document.getElementById("GridView1").rows[2].style.display = "none";后台隐藏
GridView.Columns[2].Visable=false;
这样可以?
if (e.Row.RowType == DataControlRowType.DataRow || e.Row.RowType == DataControlRowType.Header)
{
e.Row.Cells[0].Visible = false;//如果想使第1列不可见,则将它的可见性设为false 并且判断分页,使分页不会丢失
}我只是隐藏了第一列,隐藏其他列的我还没遇到过,寒一下~~~~