5,693,062 members and growing! (17,778 online)
Email Password   helpLost your password?
Web Development » ASP.NET Controls » Grid Controls     Intermediate License: The Code Project Open License (CPOL)

Selectable GridView with WaitBox

By Iwona Les

This article describes how to implement a selectable GridView control in ASP.NET.
C# 2.0, C#Windows, .NET, .NET 2.0, WinXP, ASP.NET, Ajax, VS2005, Visual Studio, Dev

Posted: 12 Oct 2008
Updated: 16 Oct 2008
Views: 5,243
Bookmarked: 23 times
Announcements
Loading...



Search    
Advanced Search
Sitemap
8 votes for this Article.
Popularity: 3.51 Rating: 3.89 out of 5
2 votes, 25.0%
1
1 vote, 12.5%
2
0 votes, 0.0%
3
1 vote, 12.5%
4
4 votes, 50.0%
5
WaterGrid.JPG

Introduction

In this article, I will present to you an extension of the GridView control built using the AJAX Control Toolkit in ASP.NET. This Web Control allows you to select a single row, and you can manage the data by selecting commands from the context menu. Additionally, while a Web request will be processing, a simple wait-box will be displayed.

Background

The aim of this project is to deliver a selectable GridView with some nice, visual effects. It's based on HoverMenuControl and AlwaysVisibleControl from the AJAX Control Toolkit. It's free to use, and very nice and simple to implement in Web applications. By adding a JavaScript, the user is able to make a selection on the GridView.

Using the Code

The data displayed in the GridView comes from ObjectDataSource filled up with data from an XML file. The column headers are static, and have to be adapted each time you change the data source. For selecting rows, you have to register the JavaScript when the actual rendering is performed. Rendering happens every time as a response to a Web Request. So you have to distinguish the current mode of the application, because if the user chooses a row to edit data, the JavaScript cannot be registered; otherwise, he won't be able to put data in the selected row.

protected void RegisterJavaScript(object sender, GridViewRowEventArgs e)
{
    if (CurrentMode != Mode.Describe)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes["onmouseover"] = 
                  "this.style.cursor='hand';";
            e.Row.Attributes.Add("onclick",
            Page.ClientScript.GetPostBackEventReference((Control)sender, 
                 "Select$" + e.Row.RowIndex.ToString()));
        }
    }
}

You can edit or delete the data from the GridView by using the context menu. Within the GridView, you can define an ItemTemplate which tells which controls will be used to display the data. In this case we use only Labels. The EditItemTemplate holds the definition of controls which will be used while editing data in the GridView (labels and textboxes).

Usually, you want to let the user know that an AJAX update has been initiated and that the request is in progress. This approach can be realized by using the AJAX Control Toolkit, and by registering events of the PageRequestManager. When the request is initiated, a WaitBox will be shown by changing the style sheet of this control. When the request is completed, we will change the stylesheet once again and hide the control.

Please notice, that the JavaScript block has to be defined below the ScriptManager definition and not in the header section.

The code below is from Default.aspx:

Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandler); 
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler); 

function BeginRequestHandler(sender, args) 
{ 
    var elem = args.get_postBackElement(); 
    var updating = document.getElementById( '<% = updatingProgress.ClientID %>' ); 
    updating.style.display = "block"; 
} 

function EndRequestHandler(sender, args) 
{ 
    var updating = document.getElementById( '<% = updatingProgress.ClientID %>' ); 
    updating.style.display = "none"; 
}

History

  • 12th October, 2008: Initial post
  • 13th October, 2008: Screen shot added

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Iwona Les


I've began programming at the Warsaw University of Technolog. Currently I'm trying hardlyWink to finish a master program at Vienna University of Technology and at the same time I'm working as Software Developer.
I'm interested in Web Development, technologies like AJAX, Silverlight, Semantic Web etc.
Occupation: Software Developer (Junior)
Company: Artaker Computersysteme GmbH
Location: Austria Austria

Other popular ASP.NET Controls articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 1 of 1 (Total in Forum: 1) (Refresh)FirstPrevNext
Generalcute....memberBAIJUMAX20:32 12 Oct '08  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 16 Oct 2008
Editor: Deeksha Shenoy
Copyright 2008 by Iwona Les
Everything else Copyright © CodeProject, 1999-2008
Web19 | Advertise on the Code Project