mardi 29 janvier 2019

how to get the selected checkbox row value in a gridview using javascript by dynamic created checkbox

i am created dynamic checkbox control in grid view but for multiple row it add with same id fro checkbox how i can get row value of selected checkbox

here is my dyanamic control at gridvie rowdatabound event

 protected void grdreport_RowDataBound(object sender, GridViewRowEventArgs e)
    {

        int temp = e.Row.Cells.Count;

        temp--;






        if (e.Row.RowType == DataControlRowType.DataRow)
        {

            if (temp >= 3)
            {



                strheadertext1 = grdreport.HeaderRow.Cells[3].Text;

                CheckBox cb1 = new CheckBox();
                cb1.ID = "cb1";
                cb1.Text = e.Row.Cells[3].Text;



                e.Row.Cells[3].Controls.Add(cb1);



            }
}

and i am getting value on button click

protected void BtnSave_Click(object sender, EventArgs e)
    {






        foreach (GridViewRow row in grdreport.Rows)
        {


            CheckBox checkbox1 = (CheckBox)row.FindControl("cb1");
            checkbox1.Checked = true;
            if (checkbox1.Checked)
            {
                string itemname = row.Cells[0].Text;
                string particular = row.Cells[1].Text;
                string qty = row.Cells[2].Text;
            }

        }



    }

but when i am getting value it gives me first row value whenever i check second row checkbox




Aucun commentaire:

Enregistrer un commentaire