I am trying to retrieve the values of Checkbox which is inside a template column, build from the codebehind dynamically.
Code for Template:
On clicking Save button of this page, am trying to retrieve the values of checkboxes.
In the above code, there are no controls available in item[test] .
cb is returning null.
Note the unique name of the column and the ID of the checkbox are same.
Please let me know how do i retrieve the checkbox.
Thanks in advance,
Mani
protected void Page_Init(object sender, EventArgs e)
{
DefineGridStructure();
}
private void DefineGridStructure()
{
GridBoundColumn boundColumn;
boundColumn = new GridBoundColumn();
RadGridAttendance.MasterTableView.Columns.Add(boundColumn);
boundColumn.DataField = "Name";
boundColumn.HeaderText = "Name";
string session_id = dt.Rows[i]["web_submission_id"].ToString();
GridTemplateColumn templateColumn = new GridTemplateColumn();
templateColumn.ItemTemplate = new MyTemplate(session_id,db);
templateColumn.UniqueName = session_id;
RadGridAttendance.MasterTableView.Columns.Add(templateColumn);
}
Code for Template:
class MyTemplate : ITemplate
{
private string colname;
protected CheckBox cbAttended;
private string query;
private string session_id;
private DataLib_oracle db;
public MyTemplate(string sessionid, DataLib_oracle dbo)
{
colname = sessionid;
session_id = sessionid;
db = dbo;
}
public void InstantiateIn(System.Web.UI.Control container)
{
cbAttended = new CheckBox();
cbAttended.Attributes["session_id"] = session_id;
container.Controls.Add(cbAttended);
cbAttended.DataBinding += new EventHandler(cbAttended_DataBinding);
cbAttended.ID = session_id;
//cbAttended.Checked = true;
//cbAttended.Enabled = false;
}
void cbAttended_DataBinding(object sender, EventArgs e)
{
string attended;
CheckBox cBox = (CheckBox)sender;
GridDataItem container = (GridDataItem)cBox.NamingContainer;
string personnel_id = ((DataRowView)container.DataItem)["personnel_id"].ToString();
cbAttended.Attributes["personnel_id"] = personnel_id;
string session_id = cBox.Attributes["session_id"].ToString();
//Eval("Attended").ToString() == "1"
//cBox.Checked = (bool)((DataRowView)container.DataItem)["Bool"];
query = " SELECT ATTENDED FROM WEB_ATTENDEES WHERE PERSONNEL_ID = " + personnel_id + " AND SESSION_ID = " + session_id;
attended = db.GetStrDescFromID(query, WebKit.ConnectionString);
if (attended=="1")
cBox.Checked = true;
}
}
On clicking Save button of this page, am trying to retrieve the values of checkboxes.
foreach (GridDataItem item in RadGridAttendance.MasterTableView.Items)
{
string test = RadGridAttendance.Columns[1].UniqueName;
CheckBox cb = (CheckBox)(item[test].FindControl(test));
}
cb is returning null.
Note the unique name of the column and the ID of the checkbox are same.
Please let me know how do i retrieve the checkbox.
Thanks in advance,
Mani