C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




please give me the code....pls....its urgent


Posted Date: 09 Aug 2008      Total Responses: 1

Posted By: ramya       Member Level: Gold     Points: 1


how to fire link button click event in repeater control in asp.net with c#..please give me the code....



Responses

Author: Vidhya    09 Aug 2008Member Level: GoldRating:     Points: 6
hi,

.Create a subclass of the System.Web.UI.WebControls.Repeater class.
.Trap the ItemCreated event.
.Add a GroupTemplate template to the control (in addition to the ItemTemplate).
.For each item created, compare it to the previous item using a custom Comparer.
.If it is different, instantiate the template and databind it using the same ItemData as the current Item.
.Override the CreateChildControls method to reset the 'last record' member.
Anyway, I think this is a very good example of subclassing ASP.NET controls and I'm still wondering why this one isn't included in the standard framework.

using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.ComponentModel;

namespace GroupedRepeater.Controls
{
/// <summary>
/// Summary description for GroupingRepeater.
/// When another group is found, render an additional template.
/// </summary>
public class GroupingRepeater : System.Web.UI.WebControls.Repeater
{
private ITemplate _groupTemplate = null;
private IComparer _comparer = null;
private static object lastvalue = null;

public GroupingRepeater()
{
this.ItemCreated += new
RepeaterItemEventHandler(GroupingRepeater_ItemCreated);
}

protected override void AddParsedSubObject(object obj)
{
base.AddParsedSubObject (obj);
}

public IComparer Comparer
{
get { return _comparer; }
set { _comparer = value; }
}

[TemplateContainer(typeof(GroupHeader))]
public ITemplate GroupTemplate
{
get
{
return _groupTemplate;
}
set
{
_groupTemplate = value;
}
}

protected override void CreateChildControls()
{
lastvalue = null;
base.CreateChildControls ();
}

private void GroupingRepeater_ItemCreated(object sender,
RepeaterItemEventArgs e)
{
System.Diagnostics.Trace.WriteLine(e.Item.GetType().Name);
if(e.Item.ItemType == ListItemType.Item ||
e.Item.ItemType == ListItemType.AlternatingItem)
{
if(e.Item.DataItem != null)
{
if(_comparer.Compare(lastvalue, e.Item.DataItem) != 0)
{
//add a header if it was different from the previous item.

GroupHeader item = new GroupHeader();

_groupTemplate.InstantiateIn(item);
item.DataItem = e.Item.DataItem;
this.Controls.Add(item);

item.DataBind();
}
}
lastvalue = e.Item.DataItem;
}
}

public class GroupHeader : Control,INamingContainer
{
private object _dataItem;

public virtual object DataItem
{
get
{
return _dataItem;
}
set
{
_dataItem = value;
}
}
}
}
}

That's it! I hope you find this useful.

Note:
Rate this content if it really helps!



Post Reply
You must Sign In to post a response.
Next : To Anil Pandey
Previous : How to insert for button click event
Return to Discussion Forum
Post New Message
Category: ASP.NET

Related Messages



dotNet Slackers   BizTalk Adaptors    Web Design

email fax service

Contact Us    Privacy Policy    Terms Of Use