具体需求是这样的: 一个表格,表格中的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);
}
列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);
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货