Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- namespace FindRowInPagedGrid
- {
- public partial class _Default : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- }
- /// <summary>
- /// Finds the item number, whatever page it's on.
- /// </summary>
- /// <param name="itemnumber">the global item number to find</param>
- protected void SelectRow(int itemnumber)
- {
- int pagesize = GridView1.PageSize;
- int targetpage = (int)Math.Floor((decimal)itemnumber / (decimal)pagesize);
- int targetitem = itemnumber % pagesize;
- GridView1.PageIndex = targetpage;
- GridView1.SelectedIndex = targetitem;
- }
- protected void SelectRow(string searchData)
- {
- int i = 0;
- int theRow=0;
- //how to iterate over the whole grid
- GridView1.AllowPaging = false;
- GridView1.DataBind();
- for (i = 0; i < GridView1.Rows.Count; i++)
- {
- //cell 2 is the data column, don't forget the command column.
- TableCell thisCell = GridView1.Rows[i].Cells[2];
- if (thisCell.Text == searchData)
- theRow = i;
- }
- //rebind after finding the page
- GridView1.AllowPaging = true;
- GridView1.DataBind();
- SelectRow(theRow);
- }
- protected void Button1_Click(object sender, EventArgs e)
- {
- SelectRow("California");
- }
- protected void Button2_Click(object sender, EventArgs e)
- {
- SelectRow("Wyoming");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement