Forms Data Controls :: SelectedValue After A Column Has Been Sorted?
Nov 2, 2010
Using ASP.NET 4.0 with C#.
I have a GridView and have sortable columns. When a column is sorted the GridView automatically selects the top row, however the SelectedValue is still representing the row before the column is sorted. The SelectedValue of the GridView only gets changed when a row is selected, but I want that to happen when the GridView is sorted.
For example if I have this in my code:
[Code]....
itemId is populated with the old SelectedValue not the new one after the GridView has been sorted.
I have a dropdownlist in DetailsView to which items are added programmatically during DataBound event. It is working fine in InsertItemTemplate, but in EditItemTemplate i am getting this error "'branchDDL' has a SelectedValue which is invalid because it does not exist in the list of items. Parameter name: value".
I have a stored procedure in my database that sorts a dataset by distance from the specific address input by the user. The distance is created among each individual users query and the sorting of distance occurs within my stored procedure, the distance is not returned in the output. Is there a way I can create a temporary column that returns the distance so that I can give the user an option to sort by distance?
I have a gridview control connected to a sqldatasource control. I am allowing the user to sort the columns in the gridview control. The user can click a row and visit another page. When they return I need to set the column sort again. I have seen that I can use the Sorting event to set the sort order of the data when I return to the page in the Sorting event. But before I leave the page where can i get the column it is currently sorted on along with the direction?
I see from google that this is a common problem. I have a SQL server database that contains 26 rows of data. Two columns, the first is PK and an identity column (keys numbered 1 to 26) and the second column is a text field (nchar(10)) containing a letter of the alphabet (A..Z). The letters were inserted randomly to simulate sql being unsorted by default. I have a query that returns all of the data ordered by the letter column ascending. If I execute the query in sql server I get 26 rows orderd A..Z.
I have a gridview that is set up for paging (page size = 15) and sorting. When sorting is disabled, all data is correctly displayed on the gridview, 15 rows on the first page, 11 rows on the second page.
If I enable sorting, I get 15 rows on the first page and 11 rows on the second page, however on closer examination I find two letters missing and two letters duplicated on both pages. If I navigate to page two, then back to page 1 I find that the data is then shown correctly and the missing letters are back.
Has anyone struck this issue? I am thinking that the sort is not being initialized correctly, but am not sure where to look.
I am building a SortedList object for use as the DataSource of a GridView control. The key-value pairs are being built manually with the "key" fields being inserted in already sorted order. The "key" column is invisible with the "value" column the single displayed data item. I set the DataSource property of the gridview to the sortedlist and call the Bind method. The gridview then displays the data in random fashion!
So I have a gridview that is sortable. I also have enabled it to export to excel. The problem is that it exports the original datasource and not the sorted data on the screen. What I need is when the export control is fired, the exact gridview or newly sorted gridview is sent to an Excel spreadsheet. Here what my excel export looks like:
I've got a Gridview bound to an objectdatasource. Sorting is enabled in gridview, but objectdatasource isn't doing any sorting. I can pick up the unsorted datatable from the Selected event of the objectdatasource, but I really want the sorted version. Is there any event on the gridview where I can access the sorted dataview it must be using internally?
Why am I asking? We're using paging as well (i.e. truncated data in gridview) and I want to loop through the full sorted dataview to find the primary key value to set selectedindex.
I have a gridview which displays images as shown in the code below. When the page loads the images load fine. But when any of the columns are sorted, the images are not displayed. In the page source view the grid still hold reference to the images when they were first loaded.
How do i bind the images so that they sort when the other columns are sorted.
Is it possible to have 2 ListBox then when a Button is Click the Items is Sorted already to GridView accordingly. btw I have done a sort button but for LB1 only. and LB2 only.
I have a GridView that sorts and has paging features. I need to grab the data from the SORTED DATA from the GRIDVIEW and put it into a DataTable. Who Do I get that sorted data gridview and store it into a DataTable. I am an ASP.NET Programmer. Goal: Get and Store Sorted GridView Data into a DataTable.
I am having a DOB field in database of type Datetime.I am retrieving this into a gridview .I want to display only date into the gridview in 'DD-MM-YYYY' format and that to in sorting order. How can I do that. I know that by converting DOB to varchar and using SQL Date formats codes(103,105...) I can do that but I can't able to display in sorted order as it will check only the date part and sort the dates. It will not chk the month & year. And I also want the user to insert the date in 'DD-MM-YYYY' format and this to be stored in database. How can I do this? Pls respond me ASAP.
I'm trying to extend the GridView control to enable sorting and paging for any situation.
When using my control I am fetching data from a database and filling a DataSet with it, then binding the GridView upon every page load. My first question would be, is this the correct approach?
To sort the GridView I am overriding the OnSorting method which stores the sort expression and direction in the ViewState, then creates a DataView and utalises the Sort method to sort the underlying data. It then sets the Data Source to this DataView and rebinds the GridView.
Paging is handled by OnPageIndexChanging which simply sets the PageIndex property and again rebinds the GridView.
My problem is; when any control causes a postback my GridView is no longer sorted, presumably because it is persistently rebound. If I don't rebind it then the GridView is empty on postback since the data isn't automatically stored in the ViewState. I have considered saving the data source in the ViewState but I would assume that this is bad practice for large amounts of data? - also DataViews are not seralisable.
The only solution I can think of currently is to override OnDataBound and sort the data every time. This results in a double sort when paging triggers a postback which seems inefficient. Code illustration of this below,
[Code]....
I'm looking for the cleanest 'best practice' solution as this is a learning exercise more than anything else.
I have a FormView with an EditItemTemplate. In the EditItemTemplate I have a RadioButtonList. I want to populate the selected button from the database. My code looks like this (simplified):
[Code]....
The stored procedure usp_GetOrderDetails returns a char(1) column called "side" which can have values of 'B' or 'S'. If it's a B or an S I want to select the correct item in the RadioButtonList, radSide. Is this possible? I've done it for my Text boxes and dropDownLists on the same form OK, I just can't figure out the RadioButtonList.
My page has a gridview, and the gridview has a TemplateField called "Acciones" (Actions). The column Acciones has a ImageButton with CommandName "Select" and CommandArgument "Tutor". Thus, the GridView has controlled event "SelectedIndexChanged". The idea is that in GV_SelectedIndexChanged, I must to set DropDownList's SelectedValue property. But, the value seted in this function don't affect the rendered dropdownlist. The debugger talk's that the value is correctly seted, but the visual result don't.
i want to display selectedvalu on dropdonwlist i have a access table like this;1 Adana2 Ankaraits displaying the numbers of cities but i want to display name of the cities in my gridview how can i fix that ? im using theese codes for register page;
string baglan =DugunSitemiz.Properties.Settings.Default.baglan; OleDbConnection conn = new OleDbConnection(baglan); conn.Open();
Using VB.Net/Asp.Net 2008, web app with Master page.I have a content page where all of the content is wrapped in an UpdatePanel that uses a UserControl called GetEmployee.ascx that I created.
In the user control I have a listbox filled with employeeIDs for the DataValueField, in fact for testing to make sure I'm getting the ID I temporarily set the DataTextField to employeeID also. Anyways I keep getting "" error saying I have not selected anything even when I do so I put a breakpoint and set a watch to find out selectedIndex, value and item and nothing.
after the user selects an employee they should click on the "select employee" button so I have some code there to find out which employee was selected. I have events setup in the GetEmployee.ascx user control to get the value selected:
[Code]....
and I have a breakpoint and it hits the "selectedIndexChanged" event first so I put a watch there and see the following.
I'm populating a dropdownlist in a formview with a different datasource from the formview's. I need to set the selected value according to the value in the formview's datasource but I'm having a hard time doing that.
Here's the code: <asp:FormView ID="FormView1" runat="server" DataKeyNames="ID" DataSourceID="SqlDataSource1"> <EditItemTemplate> [code]....
I'm using a FormView which has odsMain as the datasource. I am also using a dropdownlist which is being populated with objectdatasource odsddl.
I'd like to set the selectedvalue of the dropdownlist with the value contained in odsMain (the current record value for it). Is there any way this can be done?
The question has probably been raised many times, but I could not find an answer so far.The error is: ropdownlist has SelectedValue which is invalid because it does not exist in the list of items.However, I have debugged the values and the list has the correct list of values which includes the SelectedValue.
How would I go about populating a textbox within a FormView with the SelectedValue of a GridView? I'd like to know how to do this with the GridView on the same page as the FormView or a GridView passing a parameter from another page.