GridView Select command enables you to provide the functionality to select a particular row of GridView DataBound control in ASP.Net web pages. AJAX server controls can be used to avoid the whole page postbacks and page refresh on GridView Select command events.
In this example we will use the Northwind default database of SQL Server. For using AJAX in your GridView Select sample drag and drop the ScriptManager on top of the web page. Then next AJAX control UpdateProgress to display the visual feedback of update while loading data to the GridView control or on GridView Selection change. To avoid the page refresh on user click events while interacting with ASP.Net web page you have to use AJAX UpdatePanel control. Place the GridView Control inside it.
HTML code:
Notice the bold fonts string in the above HTML code: OnSelectedIndexChanging = "grdCategories_SelectedIndexChanging" This OnSelectedIndexChanging event handles the GridView Select. To display the change in style of selected row of GridView control, add the SelectedRowStyle properties as shown in the above code.
C# code for GridView Select with ASP.Net AJAX:
protected void grdCategories_SelectedIndexChanging(object sender, GridViewSelectEventArgs e) { grdCategories.SelectedIndex = e.NewSelectedIndex; bindGridView(); }
Download C# AJAX GridView Select Sample Code at the bottom of this article.
Now you will say; what is the use of only GridView Select without any other action on that particular selected GridView row? You are right. Next we will learn the use of select command of GridView control to get the related data of selected row in First GridView control into other appropriate ASP.Net Server control.
Download the full source code here:
ajax gridview select.zip (3.00 kb)
Currently rated 1.0 by 1 people
Tags: asp.net, ajax, ajax gridview select, ajax updatepanel, ajax scriptmanager, ajax sample, ajax gridview sample, asp.net ajax extensions, asp.net gridview selectedindexchanging
8/23/2008 9:01:19 PM