0
我需要在gridview.Iam中的checkboxfield中設置列索引以在隱藏字段上設置列索引。 有什麼辦法來設置CheckBoxField字段列索引?我否則怎麼可以添加CheckBoxField字段和隱藏字段中 模板領域的GridView在gridview中的模板字段中添加複選框字段和隱藏字段
private void BindGridcolumns()
{
try
{
DataTable dtData;DataTable copyDataTable;
dtData = (DataTable)Session["datagrid"];
copyDataTable = dtData.Copy();
copyDataTable.Columns.Remove("ServicesId");
copyDataTable.Columns.Remove("CategoryId");
copyDataTable.Columns.Remove("Services");
copyDataTable.Columns.Remove("Category");
int columnindex = 2;
Color previouscolor = ColorTranslator.FromHtml("#e34e08");int j = 1;
foreach (DataColumn datacol in copyDataTable.Columns)
{
CheckBoxField ck = new CheckBoxField();
ck.DataField = datacol.ColumnName;
ck.HeaderStyle.BackColor = previouscolor;
ck.ItemStyle.Width = 10;
ck.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
ck.HeaderText = datacol.ColumnName.Substring(2, datacol.ColumnName.Length - 2);
gv_services.Columns.Insert(columnindex, ck);
columnindex++;
}
}
catch (Exception ex) {
Page.ClientScript.RegisterStartupScript(
GetType(), "msgbox", "alert('" + ex.Message.Replace("'", "") + "');", true
);
}
}