Asynchronously update asp.net repeater as and when data changes - c#

I want an asp.net repeater control to update by itself as and when the actual data that it's pointing to, gets updated. I'm not looking for a solution where a button click happens and each time repeater(which is inside an updatepanel) is bound to a datasource.
Ex: In my page load, I have this
Page_Load(){
myRepeater.DataSource = ListOfStringObj;
myRepeater.DataBind();
}
Now, if at some point ListOfStringObj gets updated, then the repeater should reflect the changes without explicitly binding it again to the datasource.
Is this even possible? I'm not particular about repeater control here, it can be a gridview as well. If not can anyone please explain?
PS: Something of this sort is possible using Knockout js, which is based on MVVM
Thanks,
Sharath

I hope this MVVM for ASP.NET will help you to achieve this: asp.net MVVM

Related

MVC Telerik DropDownList Setting First item OnLoad

I have a MVC Telerik DropDown List. I am getting the Data through Ajax Binding. On the Page Load I want the First SelectList Item to be Autopopulated. What is the best way of achieving this.
After Googling and educating how Telerik AjaxBinding works. I came to a conclusion that Ajax binding will activate the call only when the Dropdown is Clicked.
Best way of achieving my requirement?
Thank You
You could force the DropDownList to fetch its data when the page is loaded via the fill method
$('#ComboID').data().tComboBox.fill()
Or add that one value initially on the server side via the Items method.

Databound repeater nested in GridView will not update

I have a Repeater nested inside of a GridView. On the RowDataBound event for the GridView, I set the DataSource (based on one of the row's columns) and then bind the Repeater. This works fine for the initial load, however I need to be able to add new items to the Repeater dynamically.
I append an item to the DataSource, save it to the ViewState, and where I would normally bind using a method call, I bind to the object saved to the ViewState instead. The DataSouce reflects the change, however the page does not.
What am I missing? I have the exact same setup on another page without the nesting and it works perfectly.
if (ViewState["RepeaterObj"]!=null)
{
rpt.DataSource=(IList<DataTransferObject>)ViewState["RepeaterObj"];
}
else
{
rpt.DataSource = controller.GetObj(param);
rpt.DataBind();
}
I ended up resolving the question by cutting out use of the ViewState entirely, though I thought my temporary DataSource would be lost across the postback it wasn't. I ended up going with a class-level variable which works perfectly. It seems I didn't properly understand what happens during a postback.
First of all, you shouldn't be storing a datasource in ViewState. That's pretty much the worst place you could put it.
As for your problem, I would suggest either rebinding the GridView when new items are added to the repeater, or find the repeater in the event that saves the new record and rebind it there.
I think the problem is you are not rebinding the the Repeater. You say you change how you bind to look at the ViewState object but are you actually triggering the Bind to occur? It sounds like you are not and the page is just reloading with the current data stored with the control's ViewState.
Make sure you are calling your Repeaters bind event explicitly to sure it is getting rebound.
EDIT: I suspect it might have something to do where you might need to rebind your GridView and not just the Repeater.

In asp.net , what is the difference between gridview and repeater controls

I have worked with both the controls for simple application development . Both almost do the same functionality. What is the difference between them ?
There is a table here that compares the data bound server controls:
http://weblogs.asp.net/anasghanem/archive/2008/09/06/comparing-listview-with-gridview-datalist-and-repeater.aspx
GridView always renders as a grid. Repeater allows you to create your own template layout. For instance, you can put things in divs. GridView also has a much more rich object model, while repeater is rather simplistic.
Yes, you can achieve similar results with both, but they are nowhere near the same thing.
Both these controls are Data-Bound Web Server control.
GridView : It displays data as a table and has ability to preform sort, paging,edit and delete a record.
Repeater : has fewer templates then GridView. It renders a read-only list from the datasource.

Inserting , updating and deleting of Data

I want to make a control that show list of bounded data like in grid view but I want to be able to insert new record from the same control
what is the best asp.net control I can use to do that (GridView , FormView or DetailsView)? and why?
Thanks in Advance
You can do that with all three. If you want to know how, there are some good tutorials on the official ASP.NET website, here.
The choice between them is a formatting/layout decision. A GridView produces a table, showing multiple records, while a DetailsView shows one at a time. A FormView lets you display the data however you want, but required much more effort, since you have to provide the HTML.

C# gridview nested in repeater update

My current situation is to display an unknown number of Plantypes and within those Plantypes display a list of Participants(also unknown number), the participants have a textbox and a dropdown that is editable (you can't edit the individual rows, there is one update that does a bit of validation then updates all rows.)
I currently have a gridview nested withing a repeater, the repeater displays the Plan in a label and OnItemDataBound I call a method to populate the gridviews. It looks great, but I can't figure out how to save all the data at once. I'm not opposed to handling this a different way, as in loose the gridview and or repeater, if someone has a better idea.
This is C# and framework 2.0...there is no sorting or paging on the gridviews...just some links and the fields to update.
thanks in advance,
Padawan
HTTP is stateless. Since a user physically can only update one record at a time you should implement some way to save as the user goes. This can be a simple as having a row focus and row blur events and do the saves using AJAX on blur(unfocus). Maybe make is modal as they edit so they cannot leave the page without saving.

Categories

Resources