 |
|
|
The article is really good.. but I feel providing the datasource directly is better than getting the source for the nested repeaters in ItemDataBound event.
<asp:Repeater runat="server" ID="myrep"> <HeaderTemplate> <ul> </HeaderTemplate> <ItemTemplate> <li><b> <%#((System.Xml.XmlElement)Container.DataItem).SelectSingleNode("@type").InnerText%> <br /> <asp:Repeater runat="server" ID="cric" DataSource='<%#((System.Xml.XmlElement)Container.DataItem).SelectNodes("cricketer")%>'> <HeaderTemplate> <ul> </HeaderTemplate> <ItemTemplate> <li> <%#((System.Xml.XmlElement)Container.DataItem).InnerText%> </li> </ItemTemplate> <FooterTemplate> </ul></FooterTemplate> </asp:Repeater></li> </b> </ItemTemplate> <FooterTemplate> </ul> </FooterTemplate> </asp:Repeater>
Sathy
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Thanks a lot for the thorough explained article( especially thank the generous author), I do a great aspx page with nested repeater. But when I try to print it, it came a problem: Can't print with a printer! After check all setting, I found if we viewed this page with printed review, the single page on the screen become an infinte one.
I checked each page stamps again and again, search any possible keyword on the net but I am still totally at a loss what to do.
Could any one who mastered take me out from this swamp? Any opinion will be appreciated!
Thanks for your help and patient.
sample page link as this[^]
sorry for ask twice. (the other one at http://www.codeproject.com/aspnet/Server_Nested_Repeaters.asp[^] I really need to know how to solve it, thanks. yhshih
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
I found the answer by a friend's help, The "write-mode:tb-rl" in font tag makes infinte pagination during printer review, move it to | solved it. Thaks anyway.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Only the code behind needs to be changed:
protected void Page_Load(object sender, System.EventArgs e) { LinksTableAdapters.CategoryTableAdapter Cat = new LinksTableAdapters.CategoryTableAdapter(); CategoryRepeater.DataSource = Cat.GetData(); CategoryRepeater.DataBind(); }
private void CategoryRepeater_ItemDataBound(object sender, System.Web.UI.WebControls.RepeaterItemEventArgs e) { RepeaterItem item = e.Item; if ((item.ItemType == ListItemType.Item) || (item.ItemType == ListItemType.AlternatingItem)) { PlayerRepeater = (Repeater)item.FindControl("PlayerRepeater"); LinksTableAdapters.LinksTableAdapter myItems = new LinksTableAdapters.LinksTableAdapter(); DataRowView drv = (DataRowView)item.DataItem; PlayerRepeater.DataSource = myItems.GetLinksByParameter(int.Parse(drv.Row.ItemArray.GetValue(0).ToString())); PlayerRepeater.DataBind(); } } I have 2 different tableAdapter SQL Select calls, 1 for getting the list of Categories, and 1 for getting the Items belonging to the specific category, I do this my adding a paramenter to the myItems.GetLinksByParameter() call.
I hope this is usefull
Werge
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Nish,Could u just explain me how i could bring in a Button click event in the chile repeater...
|
| Sign In·View Thread·PermaLink | 2.50/5 (2 votes) |
|
|
|
 |
|
|
Hello Nish, This is very good solution which i want. But i am getting problem in converting an object from DataItem to DataRowView as i want this code in VB.Net. i write this, Dim drv As DataRowView = CType(rptrItem.DataItem, DataRowView) But it gives me error so tell me the solution.
waiting for solution
Kevin C. Bhavsar MCA-SPU
|
| Sign In·View Thread·PermaLink | 5.00/5 (1 vote) |
|
|
|
 |
|
|
how can i do it using a database table instead of xml file. i used datatable to get teh data from the databse into the table
gIo
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
I couldn't figure out why this worked when I tried your example, but wouldn't work for me when I tried it on my own problem. Finally, after lots of frustration, I discovered that unless the child element (cricketer in your case) has at least two entries (can be empty) in at least one of the parent element instances, no relationship is set up and you get an error. To me, this looks like a bug, but I might just be missing something obvious.
System.ArgumentException: The relation is not parented to the table to which this DataView points.
Source Error:
Line 58: PlayerRepeater = (Repeater) item.FindControl("PlayerRepeater"); Line 59: DataRowView drv = (DataRowView)item.DataItem; Line 60: PlayerRepeater.DataSource = drv.CreateChildView("category_cricketer"); Line 61: PlayerRepeater.DataBind(); Line 62: } when xml looks like
<?xml version="1.0" encoding="utf-8" ?> <cricketers> <category type="Bowlers"> <cow>Betsy</cow> <cricketera>Wasim Akram</cricketera> <cricketera>Michael Holding</cricketera> <cricketera>Shane Warne</cricketera> <cricketera>Muthaiah Muralidaran</cricketera> </category> <category type="Batsmen"> <cow>Moo Moo</cow> <cricketer>Geoff Boycott</cricketer> <cricketera>Sunny Gavaskar</cricketera> <cricketera>Sachin Tendulkar</cricketera> <cricketera>Vivian Richards</cricketera> </category> <category type="Allrounders"> <cow>Yack</cow> <cricketera>Kapil Dev</cricketera> <cricketera>Ian Botham</cricketera> </category> <category type="WicketKeeper"> <cow>John</cow> <cricketera>Adam Gilchrist</cricketera> </category> </cricketers>
Notice that the cricketer tag exists only once within only one category. This causes a failure as shown above. By removing the suffixing a on one other tag in that category, giving you two cricketer tags, it works fine.
Also, I find it kind of limiting that you can't wrap a listbox control inside a repeater because the parser complains that a listitem must be the only item inside a listbox control. That kind of sucks, because it keeps you from building a list inside a nested repeater.
Javafreddie
|
| Sign In·View Thread·PermaLink | 1.33/5 (2 votes) |
|
|
|
 |
|
|
Can somebody please comment this issue? I run into the same problem with all of my own data relations.
Is it a bug? Can it be fixed?
|
| Sign In·View Thread·PermaLink | 5.00/5 (1 vote) |
|
|
|
 |
|
|
There are no event fired when databinding occurs. This code doesnt create any details at all...
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
okay, i know this is an old post but i'll respond anywayz. some new person may want to see what a solution to this problem is. nishant wrote a good article but he didn't provide _everything_. this solution may not be what he did, either. 
you need to remember to put the event in the repeater tag:
<asp:Repeater id="CategoryRepeater" OnItemDataBound="CategoryRepeater_ItemDataBound" Runat="server">
i'm assuming you've already already registered for the event in your code-behind:
CategoryRepeater.ItemDataBound += new RepeaterItemEventHandler(CategoryRepeater_ItemDataBound);
with the "public" event handler.
Jeff
|
| Sign In·View Thread·PermaLink | 1.00/5 (1 vote) |
|
|
|
 |
|
|
First of all, great article, just what I needed.
But.... how can I put a user control into the repeater? I have a simple user control that is nothing more than a combo box with a list of items and id's from a database. (Imagine a list of Countries with CountryID)
When I put the control in the web-page, it works perfectly, but as soon as I nest it inside a repeater control, I get an error: The IListSource does not contain any data sources
As far as I can see, the control shouldn't need any special processing in the ItemDataBound event, as it is all encapsulated inside the control itself...
[edit] Never mind, it was something silly I was doing!  [/edit]
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
what do the "type" and "cricketer_text" stand for here?? suppose i have a file which has nodes like name and url...how would i bind the same? can anyone help me? thanks.
|
| Sign In·View Thread·PermaLink | 3.00/5 (1 vote) |
|
|
|
 |
|
|
I've you've got a DataSet with two DataTables and appropriate DataRelations set up, you can DataBind the DataSource in the ASP.NET code directly using the GetChildRows function.
I had to write several ASP.NET reports sometime ago with multiple levels of nesting (up to 9!), and found that the fastest and easiest way to do it was to have a hefty DataSet and DataTables that covered the levels of nesting.
For your example, I would have had two DataTables:
Table 1 ("PlayerTypes"): PlayerType ---------- Bowlers Batsmen Allrounders WicketKeeperTable 2 ("Players"): PlayerType Player ---------- ------------ Bowlers Wasim Akram Batsmen Geoff Boycott Batsmen Sunny Gavaskar Bowlers Michale Holding etc.....Set up a DataRelation between them (like myDataSet.Relations.Add("PlayerTypesRel", myDataSet.Tables["PlayerTypes"].Column["PlayerType"], myDataSet.Tables["Players"].Column["PlayerType"])
Then the nexted repeaters look like (simplified from HTML lists to bold playertypes and italic players):
<asp:repeater id="PlayerTypesRepeater" runat="server"> <itemtemplate> <b><%# DataBinder.Eval(Container.DataItem, "PlayerType") %></b> <asp:repeater id="PlayersRepeater" runat="server" datasource='<%# Container.DataItem.Row.GetChildRows("PlayerTypesRel") %>'> <itemtemplate> <i><%# DataBinder.Eval(Container.DataItem, "Player") %></i> </itemtemplate> </asp:repeater> </itemtemplate> </asp:repeater> (also note that after the first level of nesting, the RowView changes to a Row too, so you use DataItem.GetChildRows instead of DataItem.Row.GetChildRows)
This is from memory and untested, but it's essentailly how I did it, and it worked great.
Hope that is useful
Ian Darling "One of the few systems...which has had “no deaths” in the reliability requirements." - Michael Platt
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Very nice...(well apart from DataBinder.Eval )...I still generally prefer to use Codebehind to provide the datasource for the nested control...but this is still a cool method...
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
I was also a big proponent of the OnItemDataBound method until recently, now I've moved to using the 'Member Method' approach, partly for the code being a bit 'clenaer' and partly for better performance (less casting, doesn't use events etc..) I posted about this here: http://www.mostlylucid.co.uk/posts/837.aspx . Also, if you don't need to use DataBinder.Eval, there's really very little reason to use it - and it can have an impact on performance since it uses reflection to determine the datatype of the DataItem - mostly unnecessary since you will already know this in most cases. You can gain around 20% in raw performance by specifying the datatype of the DataItem, e.g., ((DataRowView)Container.DataItem)["Item_Name"] for DataSets, ((DbDataRecord)Container.DataItem)["Item_Name"] for IDataReader. Anyway, interesting article but this is not the most efficient approach to doing this...
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
Nishant, the 'efficiency' argument is not an 'opinion' based one - it's just how it is... Nested repeaters are a great technique and your article is one of the few decent ones around for which you should be lauded. As I've said in my comment, I also used to use the OnItemDatabound method for nesting but I now think it is neither the simplest nor the fastest method for doing this. I don't know whether the DataBinder.Eval attitude is the general sentiment amongst ASP.NET devs, but it does mention in the QuickStarts documentation that there are performance issues with it (http://samples.gotdotnet.com/quickstart/aspplus/doc/webdatabinding.aspx). In general I prefer to use the most efficient method (and I haven't seen any arguemtn anywhere which says that DataBinder.Eval performs better than strong typing) unless there's good reason not to - in this instance there just ins't any really good reason to not use the 'better' method.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Nish,
that sure is a lot of code to get that output!
Whilst I have meaning to play with ASP.NET for quite a while [my final obstacle being removed recently with the purchase of a dedicated router/firewall allowing me to finally trust my administration of a local website], I've not managed to yet... however my XML and XSL knowledge is getting quite advanced and I'd simply solve the problem you presented with a short XSL page.
Is there any reason why I would want to use all of the ASP.NET and DataBindings type stuff? I realise that your example could just be the tip of the iceberg but fail to see it!
Regards, Ray
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
Ray Hayes wrote: I'd simply solve the problem you presented with a short XSL page.
Hello Ray
I guess, by using the XML file I might have inadvertently misplaced the focus of the article from the nested repeaters to the XML data. I'll try and make things clearer using a more-real-life example.
Lets take CP as an example case. CP has a top level category classification – C++, ASP.NET, .NET, All topics etc. Lets assume that these categories are stored in an Excel file. Under each category we have sections where some sections might belong to multiple categories. Now assume that these sections are stored in a SQL server database (each section has a field for the top-level category. Now assume that for each section we have an XML file (or a CSV file) that lists all articles under that section.
Now using nested repeaters (3 levels required) we can very easily generate a page that lists all categories/sections/articles.
The outermost repeater binds to the excel sheet’s specific worksheet/column, the middle repeater binds to the SQL server table, and the innermost repeater binds to the XML file.
The outer repeater is setup to generate a combobox that lists all categories, whose onchange event is handled to generate a page using the middle repeater. The middle repeater is setup to generate tables – one table for each section. Thus depending on the category chosen in the combobox we list those sections that are associated with that top-level category. Now the inner most repeater is used to list individual articles corresponding to each section.
I hope I have made the example clear.
So its not just about XML. The repeater control is one real cool control, and nested repeaters make it even better.
Regards Nish
Extending MFC Applications with the .NET Framework [NW] Summer Love and Some more Cricket [NW] (My first novel) Shog's review of SLASMC [NW] Nish is now the first and only CPian (as of now) to reach 16,000 forum posts on CodeProject.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
I guess I'll just have to find the time to investigate yet another string for my bow!
Not sure how my wife will cope, I've only just returned from System.Text.RegularExpression heaven and rewritten thousands of lines of C++ into half-a-dozen complex regex's -- faster and with much better error reporting.
Regards, Ray
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
 |