I am trying to use data paging (not custom data paging - just normal inefficient paging) for about max 125 records, over 5 pages, 25 records per page. But most samples out there seem to be using a gridview or a datagrid, however I want each record to look like this:
Record 1 Title
Record 1 Description
Record 1 Time: Record 1 Contact:
Record 2 Title
Record 2 Description
Record 2 Time: Record 2 Contact:
etc etc, however with grids they result is like a table with bound fields for each column so I can't display it like that using paging, I thought of using a Repeater however I think I will need to use viewstate for that as it doesn't have paging built in and don't want to use ViewState as I have disabled this - can anyone help?
I think what you are looking for is a DataView or a Repeater
The Repeater control is a basic
templated data-bound list. It has no
built-in layout or styles, so you must
explicitly declare all layout,
formatting, and style tags within the
control's templates.
Related
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.
I am developing an custom pager but stuck that how to use the functionality of Offset and Fetch in ASP.NETSELECT columns from table order by ID
OFFSET 0 rows fetch next 10 rows only
Just want a head start how i use this in my Repeater Control
Not sure what is the question, but it seems like all you need to do is something like this
SELECT columns from table order by ID
OFFSET (Page-1)*PageSize rows fetch next PageSize rows only
Where Page is a page number and PageSize - amount of items on 1 page.
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.
I got here a answer to sort the gridview.
sorting and paging with gridview asp.net
But using the above solution all the grid data sorted while clicking on the any column.
I request a solution which sorts data on the particular page only.
Suppose I have 10 pages with 50 records each page, now if I visit page 7 and sort then the only 50 records of the page 7 should be sorted.
If it just matters for the current page, avoid the hassle and use a Javascript solution.
You can also do it in ASP.NET. Grab the data you want from your DataSet, after paging (so records 350 to 400 for page 7), then change your binding from something like:
// do this
gv.DataSource = pagedDataSet.OrderBy(d => d.NameOfField);
// instead of
gv.DataSource = pagedDataSet;
If you have dynamic columns, or don't want to do write this for every possible property; see my solution in this answer.
in all the datapager examples i've seen (using a LinqDataSource tied to a ListView) the queries to the database return the full recordset. how can i get JUST the page of rows that i want to display?
for example, if i have a table with 1million rows and i want to see the 10 results on page 5, i would be getting rows 51 to 60.
i'm sure i have to implement custom paging but i haven't found any good examples.
There are many ways of doing this, however, I personally like a SQL based solution that goes to the database and gets the result set. This 4GuysFromRolla Article does a good job of explaining it.
If you're using MSSql2005, take a look at this article.
As you can see, the trick is to use the function ROW_NUMBER(), that allow you to get the sequential number of a row in a recordset. With it you can simply enable pagination based upon the number of rows you want to get in a page.
I was under the impression (from Scott Guthie's blog post "LINQ to SQL (Part 9)") that the LinqDataSource handles the paging for you at the database level:
One of the really cool things to notice above is that paging and sorting still work with our GridView - even though we are using a custom Selecting event to retrieve the data. This paging and sorting logic happens in the database - which means we are only pulling back the 10 products from the database that we need to display for the current page index in the GridView (making it super efficient).
(original emphasis)
If you are using some custom paging, you can do something like this in LINQ to SQL:
var tagIds = (from t in Tags where tagList.Contains(t.TagText) select t.TagID).Skip(10).Take(10).ToList();
This is telling LINQ to take 10 rows (equivalent to T-SQL "TOP 10"), after skipping the first 10 rows - obviously these values can be dynamic, based on the Page Size and page number, but you get the idea.
The referenced post also talks about using a custom expression with a LinqDataSource.
Scott has more information on Skip/Take in Part 3 as well.