网格视图通过 id 获取数据
本文关键字:获取 数据 id 视图 网格 | 更新日期: 2023-09-27 18:31:26
我无法得到答案,我非常需要它!
真正的问题是我确实可以通过 gridview 上的选择通过 id 获取数据,但随后我使用我在页面上实现的搜索选项,网格视图显示它获得的与结果匹配的选项,但如果我按选择它会重定向到具有错误 id 的页面, 不是要获取我选择的那个的 ID,它会获取单元格第一个位置上的字段的 ID。
这是代码:
protected void Page_Load(object sender, EventArgs e)
{
TeamGest.DBLayer.DBLTeams dbl = new TeamGest.DBLayer.DBLTeams();
GridView1.DataSource = dbl.List();
GridView1.DataBind();
TeamGest.DBLayer.DBLPlayers dbl1 = new TeamGest.DBLayer.DBLPlayers();
GridView2.DataSource = dbl1.List();
GridView2.DataBind();
}
protected void MyMenu_MenuItemClick(object sender, MenuEventArgs e)
{
{
MyMultiView.ActiveViewIndex = Int32.Parse(e.Item.Value);
int i;
for (i = 0; i <= MyMenu.Items.Count - 1; i++)
{
if (i == Convert.ToInt32(e.Item.Value))
{
MyMenu.Items[i].Text = MyMenu.Items[i].Text;
}
else
{
MyMenu.Items[i].Text = MyMenu.Items[i].Text;
}
}
}
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
GridViewRow row = GridView1.SelectedRow;
Response.Redirect("DetalhesClube.aspx?Id="+row.Cells[0].Text);
}
protected void Button1_Click1(object sender, EventArgs e)
{
string searchStringTeam = TextBox1.Text;
GetTeamResults(searchStringTeam);
}
protected void GridView2_SelectedIndexChanged(object sender, EventArgs e)
{
GridViewRow row = GridView2.SelectedRow;
Response.Redirect("DetalhesJogador.aspx?Id=" + row.Cells[0].Text);
}
protected void Button2_Click(object sender, EventArgs e)
{
string searchStringPlayer = TextBox2.Text;
GetPlayerResults(searchStringPlayer);
}
不是在查询字符串中追加row.Cells[0].Text
,而是在网格视图的 itemtemplate 中使用标签控件,在脚本端使用 eval 填充控件。填充网格视图后,标签也将填充 eval 脚本中给定的值。
现在使用 findcontrol c# 函数获取网格内标签的值,并将此值追加到查询字符串中。
参考 : 如何在 GridView 的模板字段中查找控件?