I have a list view binded to a data source.
How can I enable sorting by column?
So when clicking the column title once it sorts by ascending, click it again it sorts by descending.
Is there anything in the wizard that can be setup or it all needs to be done programatically?
If you are using a data source control then sorting can be implemented in the ListView control without having to write a single line of code - it is all handled automatically by the ListView and its data source control. Of course, in more advanced scenarios we may need to manually sort the data or programmatically.
In the following example, ListView will be sorted by ProductName and UnitPrice. simply add two LinkButtons in the ListView's LayoutTemplate with appropriate CommandName and CommandArgument property values.
<asp:ListView ID="ProductList" runat="server" DataSourceID="ProductDataSource">
<LayoutTemplate>
<h3>Product Listing</h3>
<asp:LinkButton runat="server" ID="SortByName" CommandName="Sort"
CommandArgument="ProductName">Sort by Name</asp:LinkButton>
| <asp:LinkButton runat="server" ID="SortByPrice" CommandName="Sort"
CommandArgument="UnitPrice">Sort by Price</asp:LinkButton>
<blockquote>
<asp:PlaceHolder runat="server" ID="itemPlaceholder"></asp:PlaceHolder>
</blockquote>
</LayoutTemplate>
...
</asp:ListView>
If a user clicks the "Sort by Price" link twice in a row, the first time the products will be sorted in ascending order (from cheapest to most expensive), but the second time the sort order will reverse.
That depends on the DataSource you are using. If the Data Source allows sorting, it can be set up in the way described here http://msdn.microsoft.com/en-us/library/sa88ktts.aspx . Otherwise you have to handle sorting yourself programatically. Usually that is even easier than the automatical approach.
Related
Is it possible to place a dropdown arrow in RadAutocomplete textbox, so that user can see what options are the list? Please see the screen shot
<telerik:RadAutoCompleteBox
id="Variants"
runat="server"
skin="Silk" EmptyMessage="Type here" DropDownPosition="Static" DropDownHeight="200px">
The Telerik doco states it's not possible to browse the items in the dropdown area when using a RadAutoCompleteBox.
See here: http://www.telerik.com/help/aspnet-ajax/autocompletebox-difference-with-combobox.html
I prefer using a regular RadComboBox with the following attributes e.g.
<telerik:RadComboBox runat="server" ID="ddlVariants" AppendDataBoundItems="True" EmptyMessage="Type or select a variant" MarkFirstMatch="True" AllowCustomText="True" Width="200px" CheckBoxes="True" />
This approach still allows multiple selection and dynamic filtering of items, with the ability to expand the items to manually search if required.
What is the trick to implement the following interface in ASP.NET?
I think the screenshot should explain everything.
Both dropDownLists work on SQL tables. [Categories],[Items] bound with ID_category PK/FK
Number of rows variable (by default 1 row with "Add" button)
Choosing category changes only the content of the dropDownList next to it and the content stays the same when other rows get added/deleted
"Add" button saves current setup and adds new row with either "Select value" or eventually 1st category/1st item selected
How to store previously selected categories/items and the dropDown filtering by category, while adding, changing, deleting items or some other PostBack on website?
What I have tried so far is to use Repeater with DataSet, however I have encountered several different problems:
Was unable to preserve the relations between previous dropDowns
DropDowns resetting one another
2nd dropDown losing filtering when adding new row
I can post some code but since it doesn't fully work, perhaps a totally different approach would be better. Basically I started with this tutorial. The repeater currently looks like:
<repeater>
<itemtemplate>
<dropDown DataSource="categoriesDS"
value='<%# DataBinder.Eval(Container.DataItem, "Category") %>'.../>
<dropDown DataSource="itemsDS"
value='<%# DataBinder.Eval(Container.DataItem, "Item") %>'.../>
<button CommandName='<%# DataBinder.Eval(Container.DataItem, "Button") %>'
Text='<%# DataBinder.Eval(Container.DataItem, "Button") %>' .../>
</itemtemplate>
</repeater>
Thanks in advance for any suggestions or solutions and I hope it'll be helpful for others.
Ajax Cascading DropDownlist
It is very simple to use.
I am new to asp.net and even though I have been successfully developing some decent pages
that access backend SQL server using C# code behind, I have run into a problem that I need
some nudge in the right direction on.
I need to be able to display records from a SQL datasource (could be displayed using SQLDataSource method
OR using a dataReader OR using a gridview data fill) onto a page but I need other information displayed above
and below the returned record. Its best if I show an example:
<horizontal seperator line>
Customer ID
Customer Name
Customer Address
City, ST
COLUMNS FOR THE RETURNED RECORD DATA
THE ACTUAL RECORD DATA
OTHER DYNAMICALLY CALCULATED DATA BELOW THE RECORDS
<horizontal seperator line>
And this repeats for every record that is returned
For the life of me, I can't find determine what view, template, or even best data binder or
data source control it is that I need to use to make this happen.
Thanks for anyone's assistance in advance.
dell
If a datatable or gridview won't do, you can always use a Repeater or a Listview.
In the template, you can have all the controls you want in there.
You probably need a repeater similar to this:
<asp:Repeater runat="server" ID="repeater1">
<ItemTemplate>
<hr/>
<asp:Label runat="server" ID="labelCustomerId" />
<div style="padding-left:150px">
<asp:Label runat="server" ID="labelCustomerName" />
<asp:Label runat="server" ID="labelCustomerAddress" />
<asp:Label runat="server" ID="labelCityState" />
</div>
<asp:GridView runat="server" ID="gridViewRecordData">
<!--define columns & footer calculations here -->
</asp:GridView>
<hr/>
</ItemTemplate>
</asp:Repeater>
You can use the same ItemTemplate if you chose a ListView
Repeated is the best control. but in repeater you need to write code for Paging, Sorting...etc functiontly.
If you don't want to code for paging, sorting then go for GridView.
Try a ListView control. It lets you use templates to define how records, groups of records, etc. show up. For example you could define a template for your customer contact info, then a template for your records and other data.
You can accomplish this easily with a ListView. This article has a display of product information that's a lot like your layout -- horizontal lines between repeated sections.
I also like Scott Gu's tutorial, though the data layout (catalog images) is a little different from yours. Still, there's some good screenshots, and it also demos a Linq to SQL data source, which is a popular choice.
I looking forward to find a suitable asp.net DataBound control (C#) to implement in my application.
I wanted to create a exam page where each page show 10 questions, each question got a Label control and a radiobutton control to display the choices, the data to be bind into the DataBound control might be having multiple rows where each rows represent each question.
I found that DetailView control was quite suit with my requirement but I not able to set the page size.
Please help to give some suggestion and advises, thank you in advanced.
I would use a DataList or a ListView, because it will allow you to enter a template for each item. The reason I would choose these over a repeater is because you can use data keys, which will probably come in handy.
Here's a simple example of how you could implement a list of questions:
<asp:DataList ID="DataList1" runat="server" DataKeyField="QuestionID" ...>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%#Eval("Question")%>' />
<asp:RadioButton ID="RadioButton1" runat="server" Text="Yes" GroupName="QuestionAnswer" ... />
<asp:RadioButton ID="RadioButton2" runat="server" Text="No" GroupName="QuestionAnswer" ... />
</ItemTemplate>
</asp:DataList>
I would recommend to you to use the Repeater control since you can customize it's design very easily to suit your needs.
Here are two tutorials on how to use it:
http://www.w3schools.com/aspnet/aspnet_repeater.asp
http://www.learn-asp.net/asptutorials/Repeater.aspx
Update:
Repeater doesn't have pagination included so you would have to add it:
http://blog.divergencehosting.com/2009/03/25/adding-paging-repeater/
Other option would be to just use a GridView which has pagination included.
I need to create a group of DropDownLists to show and allow change of a property group for an item.
I have the following code on my ASP page.
<asp:Repeater runat="server" ID="repeaterProperties">
<ItemTemplate>
<p><asp:DropDownList runat="server" ID="ddProperty" OnInit="ddProperty_OnInit" /><p>
</ItemTemplate>
</asp:Repeater>
The ddProperty_OnInit populates the DropDownList with all the possible values with a database query.
How can I set the selected value of each created DropDownList according to the Repeater's source data?
Let's say, for example, that we have the possible property values of A, B and C.
If the database output for the Repeater contains two of those values, A and B, the Repeater outputs two DropDownLists, both with all 3 values availabla and the first one with A as selected value and the second one with B as selected value.
Edit:
It seems that adding OnItemDataBound="repeater_ItemDataBound" to the Repeater and selecting the appropriate value in there is not the way to go in my case. This is because I also need to save the possibly changed values to a database.
The ItemDataBound event of the Repeater is fired before the OnClick event on a Button and changes the selected values to their old values before the new selections can be saved.
Any suggestion on how to work around this?
Current code:
<asp:Repeater runat="server" ID="repeaterJako" OnItemDataBound="repeater_ItemDataBound">
<ItemTemplate>
<asp:DropDownList id="ddJako" runat="server" OnInit="ddJako_OnInit">
</asp:DropDownList><br />
</ItemTemplate>
</asp:Repeater>
<asp:Button runat="server" id="updateButton" Text="Save" OnClick="update_OnClick" />
In the code-behind, ddJako_OnInit populates the drop down list with all the possible choises, while the repeater_ItemDataBound uses the method suggested by Bryan Parker to select the proper value.
Maybe I'm misunderstanding something about your question... but it seems like this is exactly what OnItemDataBound is for. :)
Use FindControl to get a reference to your DropDownList in the event handler. Also check to make sure the item is not the header/footer. The example from MSDN does both these things:
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.repeater.onitemdatabound.aspx
In regard the problem I specified in my edit, the time of the DataBind plays an important role. I used to do the databinding in the Page_Init event, which caused the repeater_ItemDataBound event to be fired before the button_OnClick event.
The solution was to move the databinding to the Page_PreRender event.
The population of the DropDownList with all the choises is still done in its OnInit event.