1
I am adding the gridview fields via code, but the checkbox does not appear, instead the check box appears: "System.Web.UI.WebControls.CheckBox"
Go on like I’m doing:
CheckBox check = new CheckBox();
if (Session["dt1"] != null)
{
dt1 = (DataTable)Session["dt1"];
}
else
{
dt1.Columns.Add("ID");
dt1.Columns.Add("Nome");
dt1.Columns.Add("Quantidade");
dt1.Columns.Add("Valor");
dt1.Columns.Add("Desconto");
dt1.Columns.Add("Valor Final");
dt1.Columns.Add("Quitar");
}
dr1 = dt1.NewRow();
dr1["ID"] = txtidprodutoAdd.Text;
dr1["Nome"] = cbProdutoAdd.SelectedItem;
dr1["Quantidade"] = UpQuantidade.Text;
dr1["Valor"] = txtValorAdd.Text;
dr1["Desconto"] = txtDescontoAdd.Text;
dr1["Valor Final"] = txtValorFinalAdd.Text;
dr1["Quitar"] = check;
dt1.Rows.Add(dr1);
GridView5.DataSource = dt1;
GridView5.DataBind();
Session["dt1"] = dt1;
This code works normally when I added the type bool and it was marked, but now I need the user to have control to mark and uncheck any gridview line.
You want to add the Checkbox inside the Grid right? If that’s what you need to add a template column, you can’t put it inside the datatable that way.
– Thiago Loureiro
But I need to create the checkbox at the time that adds the data, and I need to add it that way.
– Mariana
Yeah, but this way that you’re doing it doesn’t work. Place an object inside the datareader, you have to dynamically add the Itemtemplate column with the Checkbox in your Gridview.
– Thiago Loureiro
https://www.codeproject.com/Questions/366948/How-to-add-checkbox-in-gridview-dynamically check here to see if this is what you need.
– Thiago Loureiro
https://www.codeproject.com/Articles/13462/How-to-create-template-columns-dynamically-in-a-gr
– Thiago Loureiro
@Thiagoloureiro I know how to create it with itemtemplate, but how can I do it so that it is the last column of Grid? 'cause then he’s the first.
– Mariana