How to fire server side events of Dynamic DataList control 
April 21st, 2009, 05:14 PM
| | Newbie | | Join Date: Aug 2008 Location: hyderabad-india
Posts: 18
| | |
Hi All
This is my first query in this site. firstly i like to appreciate all the contributors of this site and solutions.
I am having an issue while using DataList dynamically. I am able to bind dynamic itemtemplate and dynamic linkbutton in that itemtemplate and displaying data and linkbuttons successfully. but i am not able to fire click event of the rendered linkbuttons even i registered the click event correctly.
also for the safe side i also registered ItemCommand event of DataList.
i have to achieve this task dynamically. there is no aspx or ascx code to be used i am using C# class file.
please revert back if you need any more information to solve my issue.
Your help is highly appricated.
Thanks
Raj
| 
April 21st, 2009, 05:33 PM
|  | Site Moderator | | Join Date: Oct 2006 Location: The Great White North :)
Posts: 4,940
Provided Answers: 8 | | | re: How to fire server side events of Dynamic DataList control
Welcome to the ASP.NET forum Raj :)
I'm glad you were finally able to post your question.
First of all, did you implement a method to handle the DataList's ItemCommand Event?
If not, try it, does this work?
If it doesn't work then it's likely that you have to bubble up the event in any custom item templates you have implemented.
| 
April 22nd, 2009, 05:57 AM
| | Newbie | | Join Date: Aug 2008 Location: hyderabad-india
Posts: 18
| | | re: How to fire server side events of Dynamic DataList control
Thank you, and because of you i am able to use BYTES. Yes i am handling ItemCommand event.
Another thing i have to mention is..my appliation is implementation of custom webpart. so there are 2 classes that i am using in my program. 1 is class which implements webpart class and another class is which implements Itemplate for creating custom template.
i am rendering all controls in CreateChildControl( ) method. also i avoided postback problem that will cause problem for dynamic link buttons.
i am placing my logic that i implemented -
public class RelatedOrganizations : System.Web.UI.WebControls.WebParts.WebPart
-
{
-
//variables
-
DataList dataListTop;
-
DataList dataListBottom;
-
-
//methods
-
protected override void CreateChildControls()
-
{
-
if (!Page.IsPostBack)
-
{
-
-
//adding properties to my datalist
-
dataListBottom = new DataList();
-
dataListBottom.ItemCommand += new DataListCommandEventHandler(dataListBottom_ItemCommand);
-
dataListBottom.SelectedIndexChanged += new EventHandler(dataListBottom_SelectedIndexChanged);
-
TemplateField tfBottom = new TemplateField();
-
tfBottom.ItemTemplate = new GridViewTemplate(DataControlRowType.DataRow, strSalesPositionDescriptionColumn);
-
tfBottom.ItemTemplate = new GridViewTemplate(DataControlRowType.DataRow, strSalesPositionIdColumn);
-
dataListBottom.ItemTemplate = tfBottom.ItemTemplate;
-
-
DataTable dt=getData();
-
dataListBottom.DataSource = dt;
-
dataListBottom.DataBind();
-
-
} //end of if
-
-
}//end of method
-
-
-
//itemcommand event definition
-
void dataListBottom_ItemCommand(object source, DataListCommandEventArgs e)
-
{
-
dataListUpdate(e);
-
}
-
-
}//end of class
-
-
//here is my class for Itemplate with a linkbutton
-
public class GridViewTemplate : ITemplate
-
{
-
private DataControlRowType templateType;
-
private string columnName;
-
-
public GridViewTemplate(DataControlRowType type, string colname)
-
{
-
templateType = type;
-
columnName = colname;
-
}
-
-
public void InstantiateIn(System.Web.UI.Control container)
-
{
-
// Create the content for the different row types.
-
switch (templateType)
-
{
-
case DataControlRowType.Header:
-
-
break;
-
case DataControlRowType.DataRow:
-
LinkButton lnkbSPDesc = new LinkButton();
-
lnkbSPDesc.DataBinding += new EventHandler(lnkbSPDesc_DataBinding);
-
lnkbSPDesc.Click += new EventHandler(lnkbSPDesc_Click);
-
container.Controls.Add(lnkbSPDesc);
-
break;
-
-
-
default:
-
break;
-
}
-
}
-
-
void lnkbSPDesc_Click(object sender, EventArgs e)
-
{
-
LinkButton lb = (LinkButton)sender;
-
-
}
-
-
void lnkbSPDesc_DataBinding(object sender, EventArgs e)
-
{
-
-
LinkButton l = (LinkButton)sender;
-
//Label l = (Label)sender;
-
-
DataListItem item = (DataListItem)l.NamingContainer;
-
-
-
POAICSharepointUtility.GetConfigKey("");
-
l.Text = DataBinder.Eval(item.DataItem, POAICSharepointUtility.GetConfigKey("SalesPositionDescriptionColumn")).ToString();
-
l.CommandArgument = DataBinder.Eval(item.DataItem, POAICSharepointUtility.GetConfigKey("SalesPositionIdColumn")).ToString();
-
l.CommandName = DataBinder.Eval(item.DataItem, POAICSharepointUtility.GetConfigKey("SalesPositionIdColumn")).ToString();
-
l.Click += new EventHandler(l_Click);
-
} //end of class
I hope this code will help you for understanding my problem.
looking for your reply.
thank you
Last edited by Frinavale; April 22nd, 2009 at 02:12 PM.
Reason: Added code tags. Please post code in [code] [/code] tags.
| 
April 22nd, 2009, 01:10 PM
| | Newbie | | Join Date: Aug 2008 Location: hyderabad-india
Posts: 18
| | | re: How to fire server side events of Dynamic DataList control
Hi
I dont know what happend, but now my problem was solved. The datalist itemcommand event firing is working fine.
Thank you.
| 
April 22nd, 2009, 02:13 PM
|  | Site Moderator | | Join Date: Oct 2006 Location: The Great White North :)
Posts: 4,940
Provided Answers: 8 | | | re: How to fire server side events of Dynamic DataList control
I'm glad that you solved your problem.
Hopefully next time we'll actually be able to help you :)
-Frinny
| 
April 22nd, 2009, 07:14 PM
| | Newbie | | Join Date: Aug 2008 Location: hyderabad-india
Posts: 18
| | | re: How to fire server side events of Dynamic DataList control
Yes frinny. i hope the same.
| 
April 23rd, 2009, 05:04 AM
| | Newbie | | Join Date: Aug 2008 Location: hyderabad-india
Posts: 18
| | | re: How to fire server side events of Dynamic DataList control
Hi Frinny
I struck with a problem for Dyanamic Grid View. i am generating a dynamic gridview by custom ItemTemplate. every thing is working except the Page Size. my gridview it not showing records in page wise even i set page size property. where as it is showing all data in 1 page.
In my code, i am only considering ItemTemplate. i am not at all considering PageSetting or PageTemplate. but i am setting gridview's page size property.
the result i am getting is all data that i will give as source to gridview are getting populated on 1 page instead of n pages that i will get with respect to my page size value.
can you explain how i can get my data populate in several pages.
| 
April 23rd, 2009, 02:18 PM
|  | Site Moderator | | Join Date: Oct 2006 Location: The Great White North :)
Posts: 4,940
Provided Answers: 8 | | | re: How to fire server side events of Dynamic DataList control
It should work...
Did you set AllowPaging="true"?
|  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 225,662 network members.
|