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

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.

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.

how to Specify Repeat times to repeater control

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.

Gridview Sorted Event

I've very small question that drives me mad :)
I've a Gridview (bind from db nothing special there) and I use small function that runs on the griviewrows and sets .Visable to false in case they don't match search criterias. It works fine but when I try to sort the grid view (by clicking on the header) all the "hidden" rows shows up again.
I tried to use the "GridView_Sorted" event in order to run on the gridview and hide again but it doesn't seem to do anything. The select statement is stored procedure so I can't use filtering expressions.
My Question is - Is there a way to run the hiding function after the sort
(as "Occurs when the hyperlink to sort a column is clicked, but after the GridView control handles the sort operation." {http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.sorted.aspx} suggests )
The GridView's PreRender event should do the trick.
You could just walk GridView.Rows and apply your logic there... That way it's guaranteed to occur at the right time wether the sort happens or not.
How are you binding the data?
Maybe it would help only to bind the used data (rows) to the grid, because binding not displayed data is kind of an overhead.

how do I create an array or list of ASP.NET checkboxlists

I know how to use the checkboxlist in ASP.NET to display options retrieved from a database. What I don't know how to do is to make this 2-dimensional. That is, I need a list of checkboxlists where I don't know how long the list is; both dimensions of the checkboxlist will be determined by
list of people (pulled from database)
list of tasks (pulled from database)
and the user of the web page will click in column/row to specify which people will be assigned which tasks.
Right now I'm thinking that my only option is to brute-force it by creating a table and populate each cell with its own checkbox. (yuck)
Is there a more elegant way to create a 2-dimensional array of checkboxes with labels for both rows and columns?
I would use a repeater along with a checkboxlist. Depending on how your database is setup you could have each checkboxlist databound.
I've done this before and resorted to the brute-force method you suggest.
It's not as nasty as you'd think. Other solutions that were declarative and databound would likely be just as convoluted and confusing.
I use the ASPxGridView from DevExpress. It has a control column type of Selected (or something like that) which will display a checkbox in the column with the other column populated from your bound datasource. The User can select any rows desired by checking the checkbox on the row and you can get all the selected rows easily inot a collection to process. DevExpress components really do get rid of a lot of brute-force programming.
You can programmitaclly use a GridView control. It's inherently two-dimensional and you can use databound CheckBoxFields for it.
If you're looking for a quick and dirty way, you can use the AJAX Control Toolkit with the two controls and can populate one based on the other. If that's not what you're looking for, I'd do it the brute force way.

Resources