1

I wasn't able to get an answer to this and i need it badly!

The problem really is that i do can trough the selects on the gridview get the data trough the id, but then i use the search option i implemented on the page and the gridview shows the ones it gets that match the result but if i press select it will redirect to the page with the wrong id, isntead of getting the id of the one i selected it gets the id of the field that was on the 1st position of the cell.

Here is the code:

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);    
}
Saeed Amiri
  • 22,252
  • 5
  • 45
  • 83
Soulforth
  • 55
  • 8

1 Answers1

0

Instead of appending row.Cells[0].Text in query string, Use a label control in itemtemplate of the grid view, use eval in script side to populate the control.once the grid view gets populated the label will also get populated with the value given in the eval script.

Now use findcontrol c# function to get the value of the label inside the grid and append this value in query string.

refer : How to find control in TemplateField of GridView?

Community
  • 1
  • 1
Thiliban
  • 74
  • 4