Click here to Skip to main content
15,899,474 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hello..
I have a funny problem with my OnRowCommand in gridview.
I`ve add a template field, button, which is bind with datakey in gridview, to update a record.
The idea is: on command btn_update, take all the fields from that record and populate textboxes with it.

C#
if (e.CommandName == "btn_update")
            {
                int id1 = Convert.ToInt32(e.CommandArgument);

                Session["naziv"] = gv_artikli.Rows[id1].Cells[1].Text;
                Session["proizvodac"] = gv_artikli.Rows[id1].Cells[2].Text;
                Session["vrsta"] = gv_artikli.Rows[id1].Cells[3].Text;
                Session["oblik"] = gv_artikli.Rows[id1].Cells[4].Text;
                Session["cijena"] = float.Parse(gv_artikli.Rows[id1].Cells[5].Text);
                Session["opis"] = gv_artikli.Rows[id1].Cells[6].Text;
                Session["participacija"] = gv_artikli.Rows[id1].Cells[7].Text;
                
                PostaviTextBox();
}
public void PostaviTextBox()
{
 txt_id.Text = Session["ArtikalID"].ToString();

              txt_naziv.Text = Session["naziv"].ToString();
              txt_cijena.Text = Session["cijena"].ToString();
              txt_oblik.Text = Session["oblik"].ToString();
              txt_opis.Text = Session["opis"].ToString();
              dp_proizv.SelectedItem.Text = Session["proizvodac"].ToString();
              dp_vrsta.SelectedItem.Text = Session["vrsta"].ToString();
              dp_partc.SelectedItem.Text = Session["participacija"].ToString();
}

That works "fine"- except: if I click for example on record which ID=4, in textboxes it will be shown records for ID=8, and so on..
Any Idea?
Also, I must mention that template field which delete records- works just fine (if ID=4 it will delete ID=4).
Posted

It sounds like an order of operations issue to me. The values get read before they get changed. page load runs before events, page prerender runs after. Set breakpoints and see what order your code is being executed in.
 
Share this answer
 
It was problem with button field. The button field had CommandArgument="idArtikal" (bounded with datakey).
When I removed command argument, it work fine!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900