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

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.

Related

Refresh drop down list

I have a drop down list that is populated based on the selected value of another drop down list. The main drop down list is dlJobName. It contains the list of all active jobs. The second drop down list is dlStage. This contains the distinct stage values related to the JobName. Here is the query that populates the dlStage drop down list.
SELECT DISTINCT [AnnotationDate] as Annotation_Date FROM [vw_GridviewSource] WHERE ([Name] = #Name)
In this code the AnnotationDate is not a date field but a text field. #Name is a variable equal to the selected value from the dlJobName list.
Here is my dilemma. When I make a selected_index_change event for the dlJobName, before I update the gridview that uses both of these drop down lists, I need to update the dlStage to only available values. What is happening is the dlStage list is not updated and the values in the drop down list is not available for the new JobName. Is there a way to force the query to run on the dlStage drop down list in conjunction with the selected index change event? This would cause the gridview to at least populate and not error out.
I can provide whatever additional code is necessary.
I think you have not set AutoPostBack="true" of drop down list. If Problem continues please put your HTML and cs code for proper help.
Hi maybe like other user comment you need go to property from dropdownlist, search AutoPostBack and change False for True. Don't forget clean firsr your dropdownlist
DropDownList.Items.Clear() (VB.NET)
DropDownList.Items.Clear(); (C#)
After clean your dropdownlist charge again your method to bind dropdownlist
set the property
dlJobName.AutoPostBack="true"
This will makes the SelectedIndexEvent to fired when the selected index of the main dropdown is changed.
In that selectedIndexChanged Event load the second DropdownList.
Here is an example,
http://asp-net-example.blogspot.in/2009/03/how-to-use-dropdownlist-autopostback.html
Hope your problem solved, if still exists kindly paste your snippet.

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.

Is it possible to have a SQLDataSource with a parameter that is based only upon the GridView that is binding to it?

I have a scenario where I want to put four identical Gridviews on the same page. (They will be on different tabs in an Ajax TabControl.) They show the same source data, but there are four corresponding groups of source data in a common underlying table. So I want to show Group 1 on Tab 1, Group 2 on Tab 2, etc. These Gridviews contain complicated controls, so I would prefer to use the same data source for all of them to avoid unnecessary repetition. The Insert and Update commands are completely identical.
So in theory I could build the Select command in such a way that I could filter the data based on the GridView that is binding to the SQLDataSource. The problem is that if I use the same SQLDataSource for all the Gridviews, I cannot find a way to have each GridView tell the SQLDataSource which one is calling it. I am thinking maybe this is not possible, because the SQLDataSource binds first before it knows what is binding to it, but I'm not sure. Can anyone think of a way to do this?
You can change the parameter value dynamically using OnSelecting event of SQLDataSource. This can be done in server side code.
Create a property which holds your current gridview unique key, which is causing SQLDataSource to fetch data from SQL database.
Assign this property unique gridview key on DataBinding event of gridview.
Based on this property change the parameter in OnSelecting event of SQLDataSource.
Let me know if I am missing something.

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