.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

How to order by LastName when using GridView and ObjectDataSource?

Posted By:      Posted Date: September 19, 2010    Points: 0   Category :ASP.Net

I have a GridView setup using ObjectDataSource to GetAllUsers, but it's automatically ordering by UserName.  How can I get this to automatically order by LastName?

<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False" DataSourceID="allUsersDataSource" >
                <asp:TemplateField HeaderText="Last Name">
                        <asp:Label ID="LastNameLabel" runat="server" Text='<%#Profile.GetProfile(Eval("UserName").ToString()).LastName%>' />

View Complete Post

More Related Resource Links

Gridview (bound by ObjectDataSource) Sorting - VB.NET

Hello.. I have a gridview being data bound by an objectdatasource which points to a BLL/DAL.  I have paging and sorting enabled within the gridview. I have the fields configured in the look/fell I want from a templatefield.  This templatefield has the sort expression (date) I want things to be sorted by. All this works as it should and I have no issues with it. But, the issue is that when I click on the header to sort asc/desc by date, I have to click on it twice for it switch to descending order.  E.g.  I hit the webpage and it lists all the information in the gridview, sorted by date, ascending order.  If I want to sort by descending order, I have to click the date header twice in order for the gridview to sort the information in descending order; the clicks cause a post-back and the whole screen is refreshed. Any ideas why this may be occurring?  Thanks.. -Jeff  

Gridview Objectdatasource calling funtion while paging

Hi,I am asking this question in bit confused state..I have a Gridview in a page which is bind to function via ObjectDataSource. Function returns dataset. I am returning dataset becuase its disconnected...but when navigating/ or using paging the see a call to the function again.. why is that? if dataset already has data then why it needs to go and make a call to DB again? please explainThanks

Edit GridView Row with ObjectDataSource


Hi together,

I have a grid that receives products over a GetList methods via ObjectDataSource. The Product class contains also a Object Supplier. If I change in the drop down list of the grid the supplier for a product and I click update the ID of the suppliier is still the same. I have debugged the call of the update method and checked the parameter in the product object.

I wrote the following code in the SelectedIndexChanged event and the text box shows the right id but not the update method.

DropDownList supplier = (DropDownList) sender;
txtTest.Text = supplier.SelectedValue;

Here is the code of my grid view:

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
    DataSourceID="odsParts" CellPadding="3" AllowPaging="True"
    CaptionAlign="Left" Width="700px" DataKeyNames="ID,Supplier">
        <asp:CommandField ShowSelectButton="True" />
        <asp:BoundField DataField="Description" HeaderText="Description" 
            SortExpression="Description" />

        <asp:TemplateField HeaderText="Supplier" SortExpression="Supplier.CompanyName">

Order of the items in a DropDownList inside GridView



I have a DropDownList inside the EditTemplateItem (if the user clicks edit) in a GridView. The DropDownList receives all available rows from the database.

My problem is, if the user clicks Edit in the GridView to edit a row and opens the DropDownList Box the original item is not selected but the first one. That means the items are sorted.

Have someone an idea how I can solve this issue that the right item / the original is selected if I change to edit mode of the grid view?

The only idear that I have is to write some lines in the code behind for the updating event and selected the suitable index manually but I think there must be an easier way.


>>>Load gridview using objectdatasource after pressing a submit button?



I'm using objectdatasource to get my data. it works fine. The
currentway how it works. When the page opens it loads the gridview.
but I don't want this.

I would like to load the gridview after I press a submit button. so in
fact after postback...

I tried to remove the select Method in aspx and set programmatically
in the submit button eventhandler but then I get an error that
Selectmethod is not set.

Can someone advice me how I can load the gridview using
objectdatasource after pressing a submit button?

DataTable and it's Gridview - A Column Order Question


Well, I've been developing with gridviews for quite some time now.  Just recently I came across a situation that has me stumped.  Here's how the gridview has been working for me.


1.      A stored procedure from the database is called (three parameters are passed (reporttype, name, location)

2.     The data is retrieved using the SqlDataAdapter to fill a Datatable


4.     Columns are created programmatically as it reads the DataTable results (headertext, datafield, and dataformatstring are set at runtime)

5.     The Gridview triggers the databind event - and voila it works.


My dilemma is this:  the stored procedure (that I haven't developed) returns a various set of columns and column order.  I have one report type that does the following:


ReportType 1:  column orders returned in the following order when running directly in SQL

            col B, col C, col D, col E, col A


when I run the report through my gridview, the column order is as follows:


WPF: how to make a GridView only sort on one column as ascending order?


We use GridView inside the Listview. We need the grid view alwasy sort on one column ascending order and not allow to click column header to change it.

Is there a easy way to achieve it in Xaml?

If not possible, how to achieve it in code behind?



Make a order by GridView


Good Morning

I am creating a order by a grid here i want to use a button that are available outside from grid on the click of this button grid display create a row and there are four column dropdown list(item_name),label display rate,textbox for insert quantity,again label for display total amount for that item. after that again display new row until user make all entry for required item.
finally a button outside of grid is submit click on this button want to save value in database.

i have created dropdown but there are add button inside gridview when i click this button all item list display in grid means if in my item master have five item then grid displaying all five row at a time.

how can i complete this task??

what i did i share with u. below is my gridview that is bind with sqldatabase and dropdown is polpulating item name and rate label display on selection of item name textbox accept quantity from user input last column calculate amount.

DropDownList in GridView with ObjectDataSource


Below is a portion of my code.  I cant seem to access "DropDownList1" in the code behind no matter which event handler I seem to use.  All I want to do is pass the corresponding value selected from the DropDownList to a method which handles the updating.

Ive tried acessing "DropDownList1" via DropDownList ddl = (DropDownList)FindControl("DropDownList1");

However this always finds no such control regardless of which eventHandler I put this code into.  Ive tried everything from OnRowDataBound to OnRowUpdated and almost everything inbetween alas the control is nowhere to be located.  Your help is much appreciated and I thank you in advance.

<asp:GridView ID="gvFields" DataSourceID="obsConfig" DataKeyNames="Name" runat="server" AutoGenerateEditButton="True"
    AutoGenerateColumns="False" OnRowDataBound="gvFields_RowDataBound" OnRowUpdating="gvFields_OnRowUpdating">
        <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" ReadOnly="True" />
        <asp:TemplateField HeaderText="Status" So

Inplace Edit in GridView

In this article I am presenting a different way to look at EditItemTemplate, using which user navigation for editing is reduced and . it looks very different (see screeen shots) then regular implementation of GridView.

GridView Confirmation Box Using JQuery BlockUI in asp.net

JQuery is the most popular JavaScript library. One of the main reasons for its fame is the plugin architecture. Anyone can create a separate library that leverage the JQuery library. In this article we are going to look at the BlockUI library which is used to block the user screen while performing a task.

Textbox Editable GridView in ASP.NET

This article describes how I made a fully editable gridview in C# using ASP.NET 2. The idea is that the GridView looks and works like an Excel spreadsheet. You see all the cells in the table, and you can edit any of the cells you like, and they are automatically updated (i.e. saved to the database). This is very often how people expect data tables to work in web pages, and I've often seen people clicking in vain on un-editable gridview cells, somehow expecting to edit them, and not understanding that they need to click an Edit button at the end of the row.

Adding Dynamic Rows in ASP.NET GridView Control with TextBoxes and with Delete functionality

In my previous examples, I have demonstrated on how to add dynamic rows in GridView control with TextBoxes and how to save the values into the database. Now, seems that most of the developers are asking if how to add a delete functionality with it. So in this example, I'm going to show on how to delete a certain row in the dynamic GridView with TextBoxes.

AJAX GridView Checkbox Select All in ASP.Net

In the previous article GridView Select Multiple Rows you learnt the multiple row selection in GridView control. Here you will get the C# code sample to select all the gridview rows using single checkbox server control. You can highlight the selected rows with different color and Font state Bold. If you want to use the selection values on different ASP.Net

AJAX GridView Paging and Sorting using C# in ASP.Net

To enable the GridView Paging and Sorting to update the GridView Data without refreshing the ASP.Net web page AJAX Extension controls are used. UpdatePanel is used to hold the GridView control that triggers the events for the controls placed inside it. By Default UpdatePanel triggers the asynchronous postbacks for its child controls.

GridView Paging Using Ajax in ASP.Net

To enable the GridView Paging and Sorting to update the GridView Data without refreshing the ASP.Net web page AJAX Extension controls are used. UpdatePanel is used to hold the GridView control that triggers the events for the controls placed inside it. By Default UpdatePanel triggers the asynchronous postbacks for its child controls.

Displaying Row Details Tooltip on GridView using JQuery

Continuing exploring JQuery! I decided to implement a feature to display some kind of details related to a row displayed on GridView. For example when displaying employees details on GridView some information might not fit in the GridView because it will make it huge and wide. These infomration can be diplayed as Tooltip. Or when you want to display a picture and some kind of formated text to be diplayed as tooltip when mouse hover on the image.
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend