Return List<> from user control & bind to parent page grid.
-
Hi, I want to return selected items (check box list) on button click of a user control to the parent page. How do I do this ? The checked items would be in form of List<>. I have made the user control but don't know how to pass an input id to it to fetch the records and on button click, return them.
-
Hi, I want to return selected items (check box list) on button click of a user control to the parent page. How do I do this ? The checked items would be in form of List<>. I have made the user control but don't know how to pass an input id to it to fetch the records and on button click, return them.
-
Just make one public method of your user control which returns List<> items [Contains selected items]. That's it. You need to access that particular method once button click is over. HTH
Jinal Desai - LIVE Experience is mother of sage....
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 pagepublic 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