In my page i am populating a GridView from code behind by setting the source a custom Datatable that i compile from an XML file, in this way i write the columns header and the rows title. And this works fine, so i am adding checkboxes in the cells while adding the columns in this way:
DataTable dt = new DataTable();
dt.Columns.Add(" ");
foreach (XmlNode xns in doc.DocumentElement.ChildNodes[0])
{
foreach (XmlNode xn in xns)
{
string tagName = xn.Name;
dt.Rows.Add(tagName);
}
}
dt.Columns.Add("Mattina Turno 1", typeof(bool)); //this adds the checkbox
dt.Columns.Add("Mattina Turno 2", typeof(bool));
dt.Columns.Add("Pomeriggio", typeof(bool));
GridView1.DataSource = dt;
GridView1.DataBind();
I am enabling each checkbox in my Gridview RowDataBound in this way:
for (int i = 0; i < e.Row.Cells.Count;i++)
{
if (e.Row.Cells[i].GetType() == typeof(System.Web.UI.WebControls.DataControlFieldCell))
{
TableCell tc = e.Row.Cells[i];
if (tc.Controls.Count > 0)
{
CheckBox cb = (CheckBox)tc.Controls[0];
if (cb != null)
{
cb.Enabled = true;
colonna = ((GridView)sender).HeaderRow.Cells[i].Text;
riga = e.Row.Cells[0].Text;
cb.CausesValidation = false;
cb.ID = riga + " " + colonna;
cb.ToolTip = riga + " " + colonna;
cb.AutoPostBack = true;
cb.CheckedChanged += new EventHandler(Cb_CheckedChanged);
}
}
}
}
}
But when i try to handle the check event of the checkbox nothing happens. The checkchanged should call Cb_CheckedChanged but nothing happens.
this is Cb_CheckChanged:
private void Cb_CheckedChanged(object sender, EventArgs e)
{
Cliccato.Text = ((CheckBox)sender).ID.ToString();
System.Diagnostics.Debug.Write(((CheckBox)sender).ToolTip);
}
Please Help me, i really need your help!
Aucun commentaire:
Enregistrer un commentaire