how to Specify Repeat times to repeater control - asp.net

I want to know about some detail of Repeater control. How can i specify the repeat counts to the repeater control.
for example i have one textbox in which user enter a digit and repeater control will show specified digit times record of repeater. How can this is possible? Can any one help.?

A Repeater loops the number of times that there are item in its data source. If you want it to repeat n times, you need a data source that has n items.
For example an array:
MyRepeater.DataSource = new int[n];
If you don't use the data source at all in the repeater other than to make it run a specific number of times, then you should perhaps use a simple loop instead of a repeater.

That's not how the repeater works. It's a data-bound control, so you assign any IEnumerable (for example a List of values) and the Repeater will repeat the output for every item in the Collection.
For more information read the MSDN article for this control.
For what you want to do, you can simply add the html code dynamically in a for loop.

Related

asp.net webform Repeater, Update a set of textbox, Add to the List / Array

I am working on old webform asp.net application which uses Repeater.
The Repeater is a set of Name and address textbox fields. I have 3 sets of Name and Address information, basically, 3 sets of records in the object list to bind.
On the UI, I changed/update one of the Name and Address. I noticed in the list, which it iterate or loops through the repeater control
foreach (RepeaterItem item in this.NameAddressRepeaterControl.Items)
I see that an extra recod is added to the items.
Question:
I am used to fixed textboxes. When I update the textbox, I write code to take Exactly what is filled in the textbox and populate the DTO object to pass to the data layer to perform database transaction to update the database records.
When the new updated record is added to the Repeater Control list, I don't know which records is updated and which is the new records.
I am checking out OnItemDataBound and OnItemCommand to see if there is a way to get the old value from one of the field and also record the value of the new value. Is this possible?
The form contains 1 Save button and it will loop through the Repeater.Items to see what Name/Address to extract, but the new and old company exist in this list.
Instead of looping through the RepeaterControl.Items, Is there a way to extract from directly the visible Repeater control? If there are 3 repeater Name/Address control, is there a way to get all the info from each of the 3 sets of Repeater controls? The Repeater wraps around a user control, NameAddressCtrl.
I prefer not to replace the Repeater controls with fixed textboxes.
Any help is greatly appreciated.
Thanks.
I reviewed the code several time and add additional code to keep track what was add and changed in the repeated and only passed the information to be saved to the db. The solution was to write additional code. I did not change anything with the repeater behavior. Thanks for the comments and help.

How to loop gridviews for each database row?

I am developing an asp.net web form application that displays some info on separate gridviews based on parameters. The second gridview depends of the values in the first one (Salida and Llegada, they work as a time range). This works only when the data displayed on the first GV has just one row.
This is how it works:
But, is there a way to loop the same gridviews for each row stored in the database? something like this:
Or maybe there is an easier option I haven't considered.
Thanks in advance.
Ok it should be simple, first sit your gridview1 paging to fetch only view only one record, Then after you fill your gridview1 i assume that you have putten an ID either as Datakeys or what ever method you have used, the index of the row should be 0 since it's always viewing one row only. Get your id and fetch your data and bind it the second gridview2.
After that on the Gridview1_Paging event you bind your data again and the use the same method above to fetch the data for the next record.
Seems a bit clunky, but the simplest option may be to add GV1 and GV2 to a repeater. Each row of the repeater would essentially be the data source for your GV1.

Showing multiple records on the same row in Gridview

May I know how to show multiple records on the same row in Gridview?
the purpose of these enumerable data bound controls is to show one record/row/object per item template. If you want to show multiple records/rows/objects you will need an intermediate step to aggregate the individual record/row/object together.
then you could bind to the gridview. however, i would recommend the ListView so you can customize the layout however you like.

Bind a Text Box to a Field Selected by SQLDataSource (VB.NET)

I'm looking for the easiest way to bind data from a SqlDataSource to textboxes dropped in Visual Studio 2008.
For example, I have 4 textboxes currently that have Address, City, State, Zip. I also have a SqlDataSource on the page fetching the ID of the record and selecting those 4 fields based on ID.
How am I able to quickly bind each box to those particular fields selected? I would think this would be really straight forward - but seems it's not. Seems like the answer is funneled towards having to create a GridView or some type of control.
Be gentle...I'm a nub :)
In general you are correct, if you want to use databinding you'll need to use an appropriate control. For this example I'd suggest using a FormView - it is designed to display the results from a single database record and uses templates, meaning you'll have complete control over the output. This article is probably a good place to start: FormView Control: Step by Step.
To read the values bound to the FormView in the code-behind class you would need to create an event handler for the FormView's DataBound event. In that event handler you would reference the controls programmatically via FindControl, like so:
Dim myLabel As Label = CType(FormViewID.FindControl("id"), Label)
Here, id would be the ID of the Label whose value you were interested in. Once you have a reference to the Label you can get its value using myLabel.Text.

ASP.NET, object data source 5+ rows returned - force repeater to only show one

Is there a way with ASP.NET to tell a data repeater which is working against a objectDataSource to only show the first row and not any others that are returned in the objectDataSource.
I can't limit the data source to one row as it's echo'ing to a grid above the repeater.
Forgive me if this is a stupid question!
Thanks in advance
C
in your repeater event handler you can use the event object to see what number the item in the collection you are on.
So you can say if that number > 0 or 1 or whatever it is, render, if not, do nothing.
It's been a really long time since I've used .NET, but I know you can lookup the index of the item in the ItemDataBound event.

Resources