我想用这些“组件”做一个搜索框:textBox,button和gridview with pagination 。在我的gridview中有姓名,姓氏和个人代码。 这个想法,用户在文本框中写入内容并按下按钮,然后在第一页中搜索角色代码,如果找到,则更改背景行,否则,继续第二页,如果找到则显示此页面并更改背景。 我有一些东西,但我的问题是总是比较第一页的白色个人代码。我的代码:
protected void Button_Click(object sender, EventArgs e)
{
string search= txtSearch.Text;
for (int pageNumber= 0; pageNumber< MyGridView.PageCount; pageNumber++)
{
foreach (GridViewRow gr in MyGridView.Rows)
{
//Cells[2] is 'personal code'
bool found = gr.Cells[2].Text.Contains(search);
if (found)
{
//MyGridView.PageIndex = pageNumber;
//MyGridView.DataBind();
MyGridView.Rows[gr.RowIndex].Style.Add("BACKGROUND-COLOR", "#aaccee");
break;
}
}
}
}
有类似的东西吗?
gr.Page[X].Cells[Y].Text
由于
答案 0 :(得分:0)
试试这个:
private bool _isStop = false;
protected void Button_Click(object sender, EventArgs e)
{
string search= txtSearch.Text;
for (int i= 0; i< MyGridView.PageCount; i++)
{
MyGridView.PageIndex = i;
//MyGridView populate page here (MyGridView_View(sender, e))
for (int j=0; j< MyGridView.Rows.Count; j++)
{
GridViewRow row = MyGridView.Rows[j];
if (row.Cells[2].Text.Contains(search)) // cell[2] is personal code as you said.
{
_isStop = true;
row.ForeColor = ColorTranslator.FromHtml("red");
break;
}
}
if (flag)
break;
}
if (!flag)
MyGridView.PageIndex = 0;
//MyGridView_View(sender, e)
}
我没有尝试过这种方法,但这会给你一些想法。