473,407 Members | 2,629 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

How to fire server side events of Dynamic DataList control

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
Apr 21 '09 #1
7 7727
Frinavale
9,735 Expert Mod 8TB
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.
Apr 21 '09 #2
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
Expand|Select|Wrap|Line Numbers
  1.  public class RelatedOrganizations : System.Web.UI.WebControls.WebParts.WebPart
  2.  {
  3.     //variables
  4.    DataList dataListTop;
  5.         DataList dataListBottom;
  6.  
  7.  //methods
  8.  protected override void CreateChildControls()
  9.         {
  10.            if (!Page.IsPostBack)
  11.               {
  12.  
  13.               //adding properties to my datalist
  14.   dataListBottom = new DataList();
  15.             dataListBottom.ItemCommand += new DataListCommandEventHandler(dataListBottom_ItemCommand);
  16.             dataListBottom.SelectedIndexChanged += new EventHandler(dataListBottom_SelectedIndexChanged);
  17.             TemplateField tfBottom = new TemplateField();
  18.             tfBottom.ItemTemplate = new GridViewTemplate(DataControlRowType.DataRow, strSalesPositionDescriptionColumn);
  19.             tfBottom.ItemTemplate = new GridViewTemplate(DataControlRowType.DataRow, strSalesPositionIdColumn);
  20.             dataListBottom.ItemTemplate = tfBottom.ItemTemplate;
  21.  
  22.     DataTable dt=getData();
  23.      dataListBottom.DataSource = dt;
  24.                 dataListBottom.DataBind();
  25.  
  26.               } //end of if
  27.  
  28.     }//end of method
  29.  
  30.  
  31.  //itemcommand event definition
  32.  void dataListBottom_ItemCommand(object source, DataListCommandEventArgs e)
  33.         {
  34.             dataListUpdate(e);
  35.         }
  36.  
  37. }//end of class
  38.  
  39. //here is my class for Itemplate with a linkbutton
  40. public class GridViewTemplate : ITemplate
  41.     {
  42.         private DataControlRowType templateType;
  43.         private string columnName;
  44.  
  45.         public GridViewTemplate(DataControlRowType type, string colname)
  46.         {
  47.             templateType = type;
  48.             columnName = colname;
  49.         }
  50.  
  51.         public void InstantiateIn(System.Web.UI.Control container)
  52.         {
  53.             // Create the content for the different row types.
  54.             switch (templateType)
  55.             {
  56.                 case DataControlRowType.Header:
  57.  
  58.                     break;
  59.                 case DataControlRowType.DataRow:
  60.                      LinkButton lnkbSPDesc = new LinkButton();
  61.                      lnkbSPDesc.DataBinding += new EventHandler(lnkbSPDesc_DataBinding);
  62.                     lnkbSPDesc.Click += new EventHandler(lnkbSPDesc_Click);
  63.                     container.Controls.Add(lnkbSPDesc);
  64.                     break;
  65.  
  66.  
  67.                 default:
  68.                       break;
  69.             }
  70.         }
  71.  
  72.         void lnkbSPDesc_Click(object sender, EventArgs e)
  73.         {
  74.             LinkButton lb = (LinkButton)sender;
  75.  
  76.         }
  77.  
  78.         void lnkbSPDesc_DataBinding(object sender, EventArgs e)
  79.         {
  80.  
  81.             LinkButton l = (LinkButton)sender;
  82.             //Label l = (Label)sender;
  83.  
  84.             DataListItem item = (DataListItem)l.NamingContainer;
  85.  
  86.  
  87.             POAICSharepointUtility.GetConfigKey("");
  88.             l.Text = DataBinder.Eval(item.DataItem, POAICSharepointUtility.GetConfigKey("SalesPositionDescriptionColumn")).ToString();
  89.             l.CommandArgument = DataBinder.Eval(item.DataItem, POAICSharepointUtility.GetConfigKey("SalesPositionIdColumn")).ToString();
  90.             l.CommandName = DataBinder.Eval(item.DataItem, POAICSharepointUtility.GetConfigKey("SalesPositionIdColumn")).ToString();
  91.             l.Click += new EventHandler(l_Click);
  92.         } //end of class
I hope this code will help you for understanding my problem.

looking for your reply.

thank you
Apr 22 '09 #3
Hi

I dont know what happend, but now my problem was solved. The datalist itemcommand event firing is working fine.

Thank you.
Apr 22 '09 #4
Frinavale
9,735 Expert Mod 8TB
I'm glad that you solved your problem.
Hopefully next time we'll actually be able to help you :)

-Frinny
Apr 22 '09 #5
Yes frinny. i hope the same.
Apr 22 '09 #6
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.
Apr 23 '09 #7
Frinavale
9,735 Expert Mod 8TB
It should work...
Did you set AllowPaging="true"?
Apr 23 '09 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: HarveyB | last post by:
I would like to generate non-modal popup windows from ASP.Net code-behind. I have tried using Client Side scripting like "function Test(){ window.open('test.htm',_blank,...
6
by: Mark | last post by:
I have been working for quite some time on this issue which in theory should be quite simple. The problem is that the Cancel and Save events are not fired when their respective buttons are...
4
by: usl2222 | last post by:
Hi folks, I appreciate any assistance in the following problem: I have a form with a bunch of dynamic controls on it. All the controls are dynamically generated on a server, including all...
1
by: Neil Jarman | last post by:
Hi, I'm new to this today, and I've got some test code (see below.) The data loads fine. I can't understand why any of the events fire. Once the page loads, clicking on thew button from the...
19
by: Daniela Roman | last post by:
Hello, I try to fire an event under a button click event and maybe anybody can give a clue please. I have let's say a WEB grid with PageIndexChanged event: private void...
6
by: erdos | last post by:
I have an asp.net 2.0 button with server and client side click events. On the first click, both events will fire. On the next click, only the client side event fires. How do I make the server...
2
by: John Kotuby | last post by:
Hi guys, I am converting a rather complicated database driven Web application from classic ASP to ASP.NET 2.0 using VB 2005 as the programming language. The original ASP application works quite...
5
by: Vili | last post by:
Hi all I am having a problem here Is it possible to fire a server side function from client side? ie. I have a function on codebehind Sub DoSomething(o as object)
3
by: Crazy Cat | last post by:
Hi all, I am developing an asp.net 2.0 application in Visual Studio 2005. On my page I have a simple datalist that is bound programmatically to a collection of simple objects. On this page I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.