Update: Ok, I created two public properties, now I want to return the selected checkbox items in the checkbox list and return them on button click so I used a foreach, not much sure about my approach.Here is how its looking now. How to bind the results with parent page gridview on user control button click ?
public partial class assets_WebControls_ftExclusions : System.Web.UI.UserControl
{
private int id; // the id passed from parent page
private ftExclusionsList myftExclusions; // the list to return to master page
public int ID
{
get{return ID;}
set{ID=value;}
}
public ftExclusionsList selectedExclusions
{
get { return myftExclusions; }
set { myftExclusions = value; }
}
protected void Page\_Load(object sender, EventArgs e)
{
// Just binding the checkbox list with selected items/total items
if (!Page.IsPostBack)
{
cblExclusions.DataBind();
ftExclusionsList myExcluList = ftExclusionsManager.ftExclusionsById(ID);
if (myExcluList != null)
{
if (myExcluList.Count > 0 && myExcluList != null)
{
foreach (ftExclusions ex in myExcluList)
{
cblExclusions.Items.FindByValue(ex.excluId.ToString()).Selected = true;
}
}
}
}
}
protected void btnUpdate\_Click(object sender, EventArgs e)
{// returning result set here how to bind it with gridview on parent page ? :(
ftExclusionsList myFTExclusionList = new ftExclusionsList();
foreach (ListItem li in cblExclusions.Items)
{
if (li.Selected == true)
{
ftExclusions myftExclusion = new ftExclusions();
myftExclusion.ftExcluId = Convert.ToInt32(li.Value);
myftExclusion.excludesc = li.Text.ToString();
myFTExclusionList.Add(myftExclusion);
}
}
selectedExclusions = myFTExclusionList;
}
}
modified on Friday, May 28, 2010 7:53 AM