怎样隐藏动态生成的表格中的列

fish_killer 2008-06-03 11:09:00
具体需求是这样的:

一个表格,表格中的textbox,label等控件都放置在一个htmltbale内,表格的一半是静态的,另一半是由代码动态生成的。
列1 列2 列3 列4
item名称 控件(textbox) 显示%(label) 详细介绍item

因为有设定了不同的访问等级,要求向访问等级不够的用户隐藏htmltable的列3和列4.
想求教一个思路怎样实现!!谢谢!

静态表单中的列隐藏已经实现,生成表格的代码如下:


private void generateForm()
{
//get all row description from table
SqlConnection sqlconn = AllStoredProcedures.sqlconnSmartReportApp();
DataSet formDesription = AllStoredProcedures.ExecuteQuery("sp_GetPLForm","isLoad", SqlDbType.Int,1,"1",sqlconn.ConnectionString);
string tbArray = "['txt1','2','1'],['txt4','1','4'],['txt5','1','5'],";
string lblPArray = "['LblpLessCostSales','1'],['LblpGrossMargin','2'],['LblpLabour','4'],['LblpOccCosts','5'],";
string lblCArray = "['LblcGrossMargin','2'],";
//Build the form
ContentPlaceHolder box = Master.FindControl("ContentPlaceHolder1") as ContentPlaceHolder;
//Build the rows
for (int i = 0; i < formDesription.Tables[0].Rows.Count; i++)
{
Label lbl = new Label();
TextBox txt = new TextBox();
Label calField = new Label();
Label calPercentage = new Label();
HtmlTableCell txtCell = new HtmlTableCell();
HtmlTableCell lblCell = new HtmlTableCell();
HtmlTableCell calcuCell = new HtmlTableCell();
HtmlTableCell percentCell = new HtmlTableCell();
HtmlTableRow row = new HtmlTableRow();
//RequiredFieldValidator reqValid=new RequiredFieldValidator();
RegularExpressionValidator expValid = new RegularExpressionValidator();
string description = formDesription.Tables[0].Rows[i].ItemArray[1].ToString();
int iscalculate = Int32.Parse(formDesription.Tables[0].Rows[i].ItemArray[2].ToString());
int descriptionID = Int32.Parse(formDesription.Tables[0].Rows[i].ItemArray[0].ToString());
string direct = formDesription.Tables[0].Rows[i].ItemArray[4].ToString();
string id = formDesription.Tables[0].Rows[i].ItemArray[3].ToString();
if (id == "") { id = "null"; }
switch (iscalculate)
{
//show the row contain input field and calculate field
case (0):
{
//add label to description
lbl.Text = description;
lbl.ID = "lbl" + id;
lblCell.Controls.Add(lbl);

//add textbox for input data
txt.ID = "txt" + descriptionID.ToString();
txt.Attributes.Add("onblur", "doCal();");
txtCell.Controls.Add(txt);
expValid.ErrorMessage = "Number Only!";
expValid.ControlToValidate = txt.ID;
expValid.ValidationExpression = "^([.]|[0-9])*[.]*[0-9]+$";
txtCell.Controls.Add(expValid);
//add id to javascript array string
tbArray += "['" + txt.ID + "','" + direct + "','" + descriptionID + "'],";

//add label to show percentage calculate field
//calcuCell.Controls.Add(calField);
calPercentage.ID = "LblP" + id;
//calPercentage.Text =
lblPArray += "['" + calPercentage.ID + "','" + descriptionID + "'],";
percentCell.Controls.Add(calPercentage);

row.Cells.Add(lblCell);
row.Cells.Add(txtCell);
row.Cells.Add(percentCell);
main.Rows.Add(row);
break;
}
//show the row only contain calculate field
case (1):
{
//add label to description
lbl.Text = description;
lbl.ID = "lbl" + id;
lblCell.Controls.Add(lbl);
//add label to show calculate field
calField.ID = "LblC" + id;
calcuCell.Controls.Add(calField);
lblCArray += "['" + calField.ID + "','" + descriptionID + "'],";

calPercentage.ID = "lblP" + id;
percentCell.Controls.Add(calPercentage);
lblPArray += "['" + calPercentage.ID + "','" + descriptionID + "'],";
//add cells into row
row.Cells.Add(lblCell);
row.Cells.Add(calcuCell);
row.Cells.Add(percentCell);
main.Rows.Add(row);
break;
}
//show the row only conatin text
case (2):
{
lbl.Text = description;
lbl.ID = "lbl" + id;
lblCell.Controls.Add(lbl);
row.Cells.Add(lblCell);
main.Rows.Add(row);
break;
}
}

}//make javascript array
tbArray += "[0,'','']";
lblCArray += "[0,'']";
lblPArray += "[0,'']";

Page.ClientScript.RegisterStartupScript(this.GetType(), "", " var tbarr = [" + tbArray + "];var lblCarr = [" + lblCArray + "];var lblParr = [" + lblPArray + "]", true);
}




...全文
216 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
烟波钓 2011-09-30
  • 打赏
  • 举报
回复
生成表格的时候 给你需要操作的<tr><td>添加runat="Server"属性,并且添加Id属性,在后台去寻找,找到后进行具体的操作

62,243

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧