.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

ListView calls ObjectDataSource SelectMethod when setting InsertItemPosition

Posted By:      Posted Date: August 27, 2010    Points: 0   Category :ASP.Net

I have a ListView that is bound to an ObjectDataSource. I want to create a new insert item when the user clicks on a button on the form. I do this by reacting to the button click event on the postback. In the button click event, I set ListView.InsertItemPosition = InsertItemPosition.FirstItem.


        protected void NewButton_Click(object sender, EventArgs e)
            // This line causes the ListView's ObjectDataSource to call its SelectMethod
            // Removing this line, the SelectMethod is NOT called.
            itemsListView.InsertItemPosition = InsertItemPosition.FirstItem;


This works, but for some reason the ObjectDataSource's SelectMethod is executed again.

Is there a reason why the SelectMethod of the ObjectDataSource is being called when the ListView's InsertItemPosition is set from None to FirstItem?


View Complete Post

More Related Resource Links

ObjectDataSource where SelectMethod returns DataTable has Delete problems


Hello experts,


I have an ObjectDataSource that is configured to use my data access layer class. The select method returns a DataTable. The DeleteMethod takes a System.Guid as a parameter. I am using a FormView object on my page that shows information from the Row of the table and allows paging. In the FormView, I also have a "delete" button with the CommandName attribute set to "Delete".

Without setting anything up, clicking the delete button would send an empty Guid to my delete method. So, I thought it was because my DataKeyNames property of the FormView was empty. So, I set the DataKeyNames property to "SystemId" which is the value from the DataRow of the current item that I would like to use as the primary key. This caused all sorts of problems basically saying that DataObjectTypeName of the the ObjectDataSource did not have a property called "SystemId". I tried adding a DeleteParameters section to the ObjectDataSource and specifying one but had no success.

Obviously, I'm missing a simple step here but I have not been able to figure it out. Below is the markup:


<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" 
    DataObjectTypeName="System.Guid" DeleteMethod="DeletePicture" 
    onobjectcreating="ObjectDataSource1_ObjectCreating" SelectMethod="GetPictures" 

ObjectDataSource SelectMethod needs to be updated at runtime


<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="CustomGetAllUsers"

MembershipUserCollection userCollection = System.Web.Security.Membership.GetAllUsers();

 protected DataSet CustomGetAllUsers( )
            DataSet ds = new DataSet();
            DataTable dt = new DataTable();
            dt = ds.Tables.Add("Users");

            dt.Columns.Add("UserName", Type.GetType("System.String"));
            dt.Columns.Add("Email", Type.GetType("System.String"));
            dt.Columns.Add("CreationDate", Type.GetType("System.DateTime"));
            dt.Columns.Add("LastActivityDate", Type.GetType("System.DateTime"));

Using ASP.NET 3.5's ListView and DataPager Controls: Displaying Data with the ListView

Prior to ASP.NET 3.5, developers who needed to display a set of records could choose between the GridView, DataList, and Repeater controls. The GridView provides rich data features, but has a very boxy layout; the DataList and Repeater allow for a more flexible layout, but lack the "point and click" data features found in the GridView, DetailsView, and FormView controls. The ListView bridges the gap between layout flexibility and built-in data features.

This article, the first in a series of articles on the ListView and DataPager controls, looks at the ListView's many available templates and illustrates how to display data. Read on to learn more!

Using JQuery to perform Ajax calls in ASP.NET MVC

The muscle behind the actual asynchronous calls comes from JavaScript. I looked around at a bunch of existing JavaScript libraries and settled on JQuery because of the way it leverages existing CSS knowledge. The three things that the library should do easily are:

WPF Tutorial - Using The ListView, Part 1

Many of the controls in WPF have a downright dizzying array of capabilities and features, due in large part to the composibility of all the components. The ListView control is a great example of this - the possibilities are almost endless. This series of tutorials on the ListView will hopefully make the space of possible options seem not quite as daunting

Setting the default start page in godaddy hosting?


 How do you set the start page with godaddy hosting? I can see no way of doing this! You do not seem to have access to the IIS settings that allow you to change it!

How to listen to events within a listview



I've got a listview and I've put a button control in one of the columns, I'm trying to figure out how I have listen to the button click within a certain row, but can't see the button in the dropdown for the IDs I can generate events for.

I'd like to get the primary key of the row that's been clicked on and then run a sql statement against it.

Any help would be appreciated.

ListView DataPager with SQL-Statements that already return only paged data.



As far as I understand the ListView-Control and the DataPager-Control, they work like this: The ListView gets its datarows from its data source, then the DataPager causes the ListView to display only a subset of those rows.

So what, when I want to use custom databinding for the ListView, that *already* gets the certain subset from SQL-Server (for better performance). Can I and how can I use the DataPager then?

Thanx, S.

Setting Screen Resolution



  I am developing a website in asp.net.How can i make my web pages view same in different screen resolutions.I am using 1024*768 resolution

Error while setting up application on Win7 using Visual Studio.NET 2003


Hi All,

Getting the below error while setting up application on Win 7 using visual studio.NET 2003.


cannot find the components for communiacting with the front page server extensions...


I understand by the error, i need to install Front page server extension, but not able to figure how to install using IIS 7.5.

I had XP machine with IIS 5.1, able to find the option.


Need your help in resolving this.




Setting default localization



I ever thought that I can set a default localization if the users one (which is set in the browser) isn't available.

I've implemented my localresource files for localization. The start.aspx.resx contains all texts and elements for German use and the start.aspx.en.resx for English users. When I switch the language in the browser settings from German to English everything works fine and the english text is displayed. But when I switch to an other language which is not German or English, it takes defaulty the german resource files.

I've set

UICulture="auto:en-US" Culture="auto:en-US"

as well, but it didn't assume the .en resource file automatically. (For example when I enter the website and switch the browser language to French or Italian it should take the english resource files.)

Thanks and regards,

Speed SQL: Tuning Your Database Calls with Tier Interaction Profiling


Tier interaction profiling (TIP) is a feature of the Visual Studio profiling tools that measures the duration of synchronous calls to ADO.NET-compliant data stores. We'll show you how TIP works and provide some best practices for using TIP to diagnose performance problems in your apps.

Mark Friedman

MSDN Magazine August 2010

Cutting Edge: ListView Tips and Tricks


This month, use nested ListView controls to create hierarchical views of data and extend the eventing model of the ListView by deriving a custom ListView class.

Dino Esposito

MSDN Magazine April 2008

Extreme ASP.NET: Client-Side Web Service Calls with AJAX Extensions


Microsoft AJAX Library and the ASP.NET 2.0 AJAX Extensions provide a number of compelling features ranging from client-side data binding, to DHTML animations and behaviors. Learn all about them here.

Fritz Onion

MSDN Magazine January 2007

WCF Essentials: What You Need To Know About One-Way Calls, Callbacks, And Events


Object and component-oriented programming have only one way for clients to call a method, but Windows® Communication Foundation introduces two more. In this article Juval Lowy explains how they work.

Juval Lowy

MSDN Magazine October 2006

Advanced Basics: Setting Word Document Properties the Office 2007 Way


The last time I wrote this column (March 2006), I shared an application that allows you to update all the Microsoft® Word documents in a folder and its subfolders. Each time the application finds a document in the specified path, it updates the document properties to match those you specified in the application.

Ken Getz

MSDN Magazine June 2006

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