Click here to Skip to main content
15,896,502 members
Articles / Web Development / XHTML

ASP.NET GridView Image Command Button Problem (Multiple PostBacks)

Rate me:
Please Sign up or sign in to vote.
4.48/5 (17 votes)
10 Oct 2008Apache3 min read 241.6K   912   42  
This article describes workarounds to solve the problem of multiple postbacks when using a command button of type image in an ASP.NET GridView (Internet Explorer).
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.ComponentModel;

namespace WebApplication
{
    [DataObject(true)]
    public class DataAdapter
    {
        /// <summary>
        /// This method is called by the ObjectDataSource when the GridView is bound.
        /// Therefore we return some dummy data sorted by the sort expression.
        /// </summary>
        /// <param name="sort">how the data should be sorted.</param>
        /// <returns>Some data</returns>
        [DataObjectMethod(DataObjectMethodType.Select, true)]
        public DataDataSet GetData()
        {
            DataDataSet data = new DataDataSet();

            data.Data.AddDataRow("hello", "asp.net", "world");
            data.Data.AddDataRow("have", "fun", "!");

            data.AcceptChanges();
            return data;
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Apache License, Version 2.0


Written By
Architect bbv Software Services AG
Switzerland Switzerland
Urs Enzler is working for bbv Software Services in Switzerland as a Software Architect.

Blogger at planetgeek.ch

Comments and Discussions