dear sir
i create a dynamic grid with a dynamic columns ,
i use a template column as followin
private
class MyTemplate : ITemplate
{
protected CheckBoxList chkbClients;
protected Label lControl;
//protected CheckBox boolValue;
private string colname;
private string colClientname;
public MyTemplate(string columnname, string columnClientname)
{
colname = columnname;
colClientname = columnClientname;
}
public void InstantiateIn(System.Web.UI.Control container)
{
chkbClients =
new CheckBoxList();
chkbClients.ID =
"chkbClients" + colname;
chkbClients.DataBinding +=
new EventHandler(chkbClients_DataBinding);
lControl =
new Label();
lControl.ID =
"lControl" + colname;
lControl.CssClass =
"'visibility:hidden'";
ClientsData clientData;
clientData =
Clients.getAllClients(Languages.Arabic.ToString());
chkbClients.DataSource = clientData.Client;
chkbClients.DataTextField =
"ClientNameE";
chkbClients.DataValueField =
"ClientID";
chkbClients.Width = 200;
Table table = new Table();
TableRow row1 = new TableRow();
TableCell cell13 = new TableCell();
TableCell cell14 = new TableCell();
row1.Cells.Add(cell13);
row1.Cells.Add(cell14);
table.Rows.Add(row1);
cell13.Controls.Add(chkbClients);
cell13.CssClass =
"width:10px; height:10px; overflow:scroll;";
cell14.Controls.Add(lControl);
cell14.Visible =
false;
container.Controls.Add(table);
}
void boolValue_DataBinding(object sender, EventArgs e)
{
CheckBox cBox = (CheckBox)sender;
GridDataItem container = (GridDataItem)cBox.NamingContainer;
if (((DataRowView)container.DataItem) == null)
{
return;
}
bool btemp = false;
if (int.Parse(((DataRowView)container.DataItem)["col1"].ToString()) > 0)
{
btemp =
true;
}
cBox.Checked = btemp;
}
public void chkbClients_DataBinding(object sender, EventArgs e)
{
CheckBoxList chkbClients = (CheckBoxList)sender;
//chkbClients.DataBind();
GridDataItem container = (GridDataItem)chkbClients.NamingContainer;
if (container == null)
{
return;
}
string clientIds = "";
clientIds = ((
DataRowView)container.DataItem)[colClientname].ToString();
clientIds +=
",";
lControl.Text = clientIds;
}
}
//class
and i use it im my code
private
void GenerateColyumns()
{
DataTable jp = journeyPlanData.Tables["JourneyPlan"];
foreach (DataColumn col in jp.Columns)
{
if (col.ColumnName.IndexOf("colClient")>=0)
{
string colId = col.ColumnName.Substring(9, col.ColumnName.Length - 9);
string templateColumnName = "col" + colId;
GridTemplateColumn templateColumn = new GridTemplateColumn();
templateColumn.ItemTemplate =
new MyTemplate("col" + colId, "colClient" + colId);
templateColumn.HeaderText =
"Day " + colId;
templateColumn.UniqueName = templateColumnName;
templateColumn.AllowFiltering =
false;
grdJPs.MasterTableView.Columns.Add(templateColumn);
}
}
}
then i add a button to loop for all rows in the grid and get the controls (check box list ) from the grid cell
how can i loop for all rows and columns to get the chec box list control from every cell ?????