[Back]


 namedescription
SelectSite OneThis is Site One
SelectSite TwoThis is Site Two
SelectSite ThreeThis is Site Three
SelectSite FourThis is Site Four
SelectSite FiveThis is Site Five
12
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
 
public partial class GridViewSelect : System.Web.UI.Page
{
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        int intSelectedIndex = 0;
        int intPageIndex = 0;
 
        int intGridViewPages = GridView1.PageCount;
 
        // Loop thru each page in the GridView
        for (int i = 0; i < intGridViewPages; i++)
        {
            // Set the current GridView page
            GridView1.PageIndex = i;
            // Bind the GridView to the current page
            GridView1.DataBind();
            // Loop thru each row in the GridView
            foreach (GridViewRow GVRow in GridView1.Rows)
            {
                // Check to see if the value of GridView cell 2 matches
                // In this example cell 1 (0) is the select link
                if (GVRow.Cells[1].Text == DropDownList1.SelectedValue)
                {
                    // If it is a mach set the variables and exit
                    intSelectedIndex = GVRow.RowIndex;
                    intPageIndex = i;
                    break;
                }
            }
        }
 
        // Set the GridView to the values found
        GridView1.PageIndex = intPageIndex;
        GridView1.SelectedIndex = intSelectedIndex;
        GridView1.DataBind();
    }
}