using System.Data;
partial class TestPage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//'Here goes the code to populate the checkbox list
DataTable dtDataTable = new DataTable();
//'Consider this as ur table dt1
Int32 intCounter = default(Int32);
dtDataTable.TableName = "TestData";
dtDataTable.Columns.Add("PageID", System.Type.GetType("System.Int32"));
dtDataTable.Columns.Add("MenuName", System.Type.GetType("System.String"));
for (intCounter = 1; intCounter <= 6; intCounter++) {
DataRow objRow = default(DataRow);
objRow = dtDataTable.NewRow();
objRow.Item("PageID") = intCounter;
objRow.Item("MenuName") = "Page" + intCounter.ToString();
dtDataTable.Rows.Add(objRow);
}
CheckboxPages.DataSource = dtDataTable;
CheckboxPages.DataBind();
PreSelectCheckBoxListValues();
}
private void PreSelectCheckBoxListValues()
{
DataTable dtPageIDs = new DataTable();
//'Consider this as ur table dt2
Int32 intCounter = default(Int32);
dtPageIDs.Columns.Add("PageID", System.Type.GetType("System.Int32"));
for (intCounter = 4; intCounter <= 7; intCounter++) {
DataRow objRow = default(DataRow);
objRow = dtPageIDs.NewRow();
objRow.Item("PageID") = intCounter;
dtPageIDs.Rows.Add(objRow);
}
foreach (DataRow drRow in dtPageIDs.Rows) {
if (((CheckboxPages.Items.FindByValue(drRow.Item("PageID").ToString())) != null)) {
CheckboxPages.Items.FindByValue(drRow.Item("PageID").ToString()).Selected = true;
}
}
}
}
|