0
我有從兩個數據庫表動態創建的複選框的矩陣(tblPrivileges,tblViews),如圖圖像:如何將dynmaically創建複選框選擇的值保存在DB
垂直記錄是從tblPrivileges和水平3條記錄來自tblViews。下面是上述矩陣代碼:
protected override void OnInit(EventArgs e)
{
int rowCnt;
int rowCtr;
rowCnt = 1;
con.ConnectionString = ConfigurationManager.ConnectionStrings["con"].ConnectionString;
SqlDataAdapter adp1 = new SqlDataAdapter("select * from tblViews", con);
DataSet ds1 = new DataSet();
adp1.Fill(ds1);
DataTable g = new DataTable();
adp1.Fill(g);
for (rowCtr = 1; rowCtr <= rowCnt; rowCtr++)
{
TableRow tRow = new TableRow();
privilegeTable.Rows.Add(tRow);
foreach (DataRow checkboxTitle in g.Rows)
{
TableCell tc = new TableCell();
//System.Web.UI.WebControls.CheckBox cb = new System.Web.UI.WebControls.CheckBox();
tc.Text = checkboxTitle.ItemArray[1].ToString();
TableCell tCell = new TableCell();
tRow.Cells.Add(tCell);
tCell.Controls.Add(new LiteralControl(checkboxTitle.ItemArray[1].ToString()));
}
}
CheckBoxList chklist = new CheckBoxList();
//SqlDataAdapter adp = new SqlDataAdapter("select v.View_ID,v.View_Name,p.Privilege_ID,p.Privilege_Name from tblViews as v right outer join tblPrivileges p on v.View_ID = p.Privilege_ID", con);
SqlDataAdapter adp = new SqlDataAdapter("select * from tblPrivileges", con);
DataSet ds = new DataSet();
adp.Fill(ds);
DataTable dt = new DataTable();
adp.Fill(dt);
foreach (DataRow name in dt.Rows)
{
TableRow tr = new TableRow();
TableCell tcTitle = new TableCell();
tcTitle.Text = name.ItemArray[1].ToString();
tr.Cells.Add(tcTitle);
foreach (DataRow checkboxTitle in g.Rows)
{
TableCell tc = new TableCell();
System.Web.UI.WebControls.CheckBox cb = new System.Web.UI.WebControls.CheckBox();
tc.Text = checkboxTitle.ItemArray[1].ToString();
tc.Controls.Add(cb);
tr.Cells.Add(tc);
}
privilegeTable.Rows.Add(tr);
base.OnInit(e);
}
}
我需要選擇複選框值和點擊按鈕後,所選擇的複選框值應該去公共表。此外,我無法設置複選框的屬性「ID」。如何將選定的複選框值保存在數據庫表中的按鈕上?
請幫忙!
我在PreInit事件中添加複選框?我會嘗試的選項,但如何獲得選定的複選框的值? – Tarun 2012-01-27 17:05:13