如何才能用js将一个GridView显示的一个列屏蔽掉
想手动在页面取消和显示一个列,这个列是GridView的模板列,要怎么样处理才可以呢,谢谢
------解决方案--------------------设置 td 的 display 为none 可以么?
------解决方案--------------------GridView.columns[i].visable=false;
------解决方案--------------------哇!一个列啊!行比较好办,列的话……
遍历每一行( <tr> ),将相应的cell( <td> )style 的display设为none.
------解决方案--------------------可以,最好你先写代码,如果不可以再修改
------解决方案--------------------function Show(){
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]);
}
}
}
}
------解决方案--------------------或者
tds[i].style.display = 'none ';
------解决方案--------------------1。
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;