R
Ryan Shaw
I’m creating a custom server control which contains a DataList.
The ItemDataBound event fires fine but the ItemCommand event does not fire.
I am calling DataBind only on non post backs but still can’t figure this out.
Bellow is the control I’m working with. I know it’s a lot but its just the
ItemCommand event which is not working.
_______________________________________________________
using System;
using System.Collections;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace MSTRWebPart
{
/// <summary>
/// Summary description for Class1.
/// </summary>
public class DisplayReport:Control,INamingContainer
{
//private MSTRFacade.Provider mstrProvider=new
MSTRFacade.Provider("D818343U-21422","Administrator","");
private MSTRFacade.Provider mstrProvider=new
MSTRFacade.Provider("localhost","Administrator","");
private ArrayList mstrProjects;
protected DropDownList ddlProjects;
protected RadioButtonList rdoFolders;
protected Button cmdGetObjects;
protected DataList dlObjects;
public DisplayReport()
{
}
protected override void CreateChildControls()
{
base.CreateChildControls ();
ddlProjects=new DropDownList();
ddlProjects.DataSource=mstrProjects;
ddlProjects.DataTextField="ObjName";
ddlProjects.DataValueField="ObjID";
Controls.Add(ddlProjects);
rdoFolders=new RadioButtonList();
rdoFolders.Items.Add(new ListItem("All", ""));
rdoFolders.Items.Add(new ListItem("My Reports",""));
rdoFolders.Items.Add(new ListItem("Shared Reports",""));
Controls.Add(rdoFolders);
cmdGetObjects=new Button();
cmdGetObjects.Text="Get Objects";
cmdGetObjects.Click+=new EventHandler(this.cmdGetObjects_Click);
Controls.Add(cmdGetObjects);
dlObjects=new DataList();
dlObjects.ItemDataBound+=new
DataListItemEventHandler(this.dlObjects_ItemDataBound);
dlObjects.ItemCommand+=new
DataListCommandEventHandler(this.dlObjects_ItemCommand);
Controls.Add(dlObjects);
if(!this.Page.IsPostBack)
this.DataBind();
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad (e);
if(mstrProjects==null)
{
mstrProjects=mstrProvider.GetProjects();
this.Page.Session["Projects"]=mstrProjects;
}
else
{
mstrProjects=(ArrayList)this.Page.Session["Projects"];
}
}
protected override void Render(HtmlTextWriter output)
{
EnsureChildControls();
ddlProjects.RenderControl(output);
cmdGetObjects.RenderControl(output);
rdoFolders.RenderControl(output);
dlObjects.RenderControl(output);
}
private void cmdGetObjects_Click(Object sender, EventArgs e)
{
//TODO: insert if statement for path selection
MSTRFacade.ProjectInfo
proj=(MSTRFacade.ProjectInfo)mstrProjects[ddlProjects.SelectedIndex];
dlObjects.DataSource=mstrProvider.GetObjectsByPath(proj.ObjName,proj.SharedReportsPath);
dlObjects.DataBind();
}
private void dlObjects_ItemDataBound(Object sender, DataListItemEventArgs e)
{
LinkButton btnLink=new LinkButton();
MSTRFacade.ObjectInfo obj=(MSTRFacade.ObjectInfo)e.Item.DataItem;
btnLink.Text=obj.ObjName;
btnLink.CommandName=obj.ObjID;
e.Item.Controls.Add(btnLink);
}
private void dlObjects_ItemCommand(Object sender, DataListCommandEventArgs
e)
{
System.Diagnostics.Debug.Write("ItemCommand:"+e.CommandName);
//dlObjects.DataSource=mstrProvider.GetObjects(ddlProjects.SelectedItem.ToString(),e.CommandName);
//dlObjects.DataBind();
}
}
}
The ItemDataBound event fires fine but the ItemCommand event does not fire.
I am calling DataBind only on non post backs but still can’t figure this out.
Bellow is the control I’m working with. I know it’s a lot but its just the
ItemCommand event which is not working.
_______________________________________________________
using System;
using System.Collections;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace MSTRWebPart
{
/// <summary>
/// Summary description for Class1.
/// </summary>
public class DisplayReport:Control,INamingContainer
{
//private MSTRFacade.Provider mstrProvider=new
MSTRFacade.Provider("D818343U-21422","Administrator","");
private MSTRFacade.Provider mstrProvider=new
MSTRFacade.Provider("localhost","Administrator","");
private ArrayList mstrProjects;
protected DropDownList ddlProjects;
protected RadioButtonList rdoFolders;
protected Button cmdGetObjects;
protected DataList dlObjects;
public DisplayReport()
{
}
protected override void CreateChildControls()
{
base.CreateChildControls ();
ddlProjects=new DropDownList();
ddlProjects.DataSource=mstrProjects;
ddlProjects.DataTextField="ObjName";
ddlProjects.DataValueField="ObjID";
Controls.Add(ddlProjects);
rdoFolders=new RadioButtonList();
rdoFolders.Items.Add(new ListItem("All", ""));
rdoFolders.Items.Add(new ListItem("My Reports",""));
rdoFolders.Items.Add(new ListItem("Shared Reports",""));
Controls.Add(rdoFolders);
cmdGetObjects=new Button();
cmdGetObjects.Text="Get Objects";
cmdGetObjects.Click+=new EventHandler(this.cmdGetObjects_Click);
Controls.Add(cmdGetObjects);
dlObjects=new DataList();
dlObjects.ItemDataBound+=new
DataListItemEventHandler(this.dlObjects_ItemDataBound);
dlObjects.ItemCommand+=new
DataListCommandEventHandler(this.dlObjects_ItemCommand);
Controls.Add(dlObjects);
if(!this.Page.IsPostBack)
this.DataBind();
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad (e);
if(mstrProjects==null)
{
mstrProjects=mstrProvider.GetProjects();
this.Page.Session["Projects"]=mstrProjects;
}
else
{
mstrProjects=(ArrayList)this.Page.Session["Projects"];
}
}
protected override void Render(HtmlTextWriter output)
{
EnsureChildControls();
ddlProjects.RenderControl(output);
cmdGetObjects.RenderControl(output);
rdoFolders.RenderControl(output);
dlObjects.RenderControl(output);
}
private void cmdGetObjects_Click(Object sender, EventArgs e)
{
//TODO: insert if statement for path selection
MSTRFacade.ProjectInfo
proj=(MSTRFacade.ProjectInfo)mstrProjects[ddlProjects.SelectedIndex];
dlObjects.DataSource=mstrProvider.GetObjectsByPath(proj.ObjName,proj.SharedReportsPath);
dlObjects.DataBind();
}
private void dlObjects_ItemDataBound(Object sender, DataListItemEventArgs e)
{
LinkButton btnLink=new LinkButton();
MSTRFacade.ObjectInfo obj=(MSTRFacade.ObjectInfo)e.Item.DataItem;
btnLink.Text=obj.ObjName;
btnLink.CommandName=obj.ObjID;
e.Item.Controls.Add(btnLink);
}
private void dlObjects_ItemCommand(Object sender, DataListCommandEventArgs
e)
{
System.Diagnostics.Debug.Write("ItemCommand:"+e.CommandName);
//dlObjects.DataSource=mstrProvider.GetObjects(ddlProjects.SelectedItem.ToString(),e.CommandName);
//dlObjects.DataBind();
}
}
}