Wrox Programmer Forums
|
BOOK: ASP.NET Website Programming Problem-Design-Solution
This is the forum to discuss the Wrox book ASP.NET Website Programming: Problem - Design - Solution, Visual Basic .NET Edition by Marco Bellinaso, Kevin Hoffman; ISBN: 9780764543869
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: ASP.NET Website Programming Problem-Design-Solution section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 20th, 2003, 04:30 AM
wak wak is offline
Registered User
 
Join Date: Oct 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Templated Datagrid Checkbox column .. Help Require

I am using a datagrid in which i m adding the templated columns in the server-side code. The column contins the checkbox control.

I am using the following code to add the column.

IDataReader drRole;
drRole = RoleObj.GetRoleNames(RoleIDs);
while(drRole.Read())
{
TemplateColumn temcol1 = new TemplateColumn();
temcol1.HeaderTemplate = new DataGridTemplate(ListItemType.Header, drRole[RoleDataDefinitions.FIELD_Name].ToString(), (int)Session["AdminLevel"]);
temcol1.ItemTemplate = new DataGridTemplate(ListItemType.Item, drRole[RoleDataDefinitions.FIELD_Role_ID].ToString(), (int)Session["AdminLevel"]);
temcol1.EditItemTemplate = new DataGridTemplate(ListItemType.EditItem, drRole[RoleDataDefinitions.FIELD_Role_ID].ToString(), (int)Session["AdminLevel"]);
temcol1.FooterTemplate = new DataGridTemplate(ListItemType.Footer, drRole[RoleDataDefinitions.FIELD_Role_ID].ToString(), (int)Session["AdminLevel"]);
this.grdModelRights.Columns.Add(temcol1);
}



Itemplate inherited Class

public class DataGridTemplate : ITemplate
{
ListItemType templateType;
string columnName;
int Level;

public DataGridTemplate(ListItemType type, string colname, int AdminLevel)
{
templateType = type;
columnName = colname;
Level = AdminLevel;
}

public void BindData(object sender, EventArgs e)
{
CheckBox cb = (CheckBox)sender;
DataGridItem container = (DataGridItem) cb.NamingContainer;
cb.Checked = true;
cb.AutoPostBack = true;

}

private void OnRightsCheckChanged(object sender, EventArgs e)
{
CheckBox box = (CheckBox) sender;
DataGridItem container = (DataGridItem) box.NamingContainer;

Label lb = (Label)container.FindControl("hdnObjectID");
string objectID = lb.Text.ToString();
}

private void OnStatusCheckChanged(object sender, EventArgs e)
{
CheckBox box = (CheckBox) sender;
DataGridItem container = (DataGridItem) box.NamingContainer;

}

public void InstantiateIn(System.Web.UI.Control container)
{
CheckBox chkRightsID = new CheckBox();
CheckBox chkStatusID = new CheckBox();
/*chkRightsID.AutoPostBack = true;
chkStatusID.AutoPostBack = true;

chkRightsID.CheckedChanged += new EventHandler(this.OnRightsCheckChanged);
chkStatusID.CheckedChanged += new EventHandler(this.OnStatusCheckChanged);*/

Literal lc = new Literal();
switch(templateType)
{
case ListItemType.Header:
lc.Text = "" + columnName + "";
if (Level == 2)
{
lc.Text = lc.Text + "
Access Status";
}
container.Controls.Add(lc);
break;
case ListItemType.Item:
chkRightsID.ID = "chkRightsID?" + columnName;
//chkRightsID.DataBinding += new EventHandler(this.BindData);
container.Controls.Add(chkRightsID);
if (Level == 2)
{
chkStatusID.ID = "chkStatusID?" + columnName;
//chkStatusID.DataBinding += new EventHandler(this.BindData);
container.Controls.Add(chkStatusID);
}
break;
case ListItemType.EditItem:
TextBox tb = new TextBox();
tb.Text = "";
container.Controls.Add(tb);
break;
case ListItemType.Footer:
lc.Text = "" + columnName + "";
container.Controls.Add(lc);
break;
}
}


Code where the problem is coming
This code executes at the button click event where I want to check the state of the checkboxes. FindControl method always returns Undefined-Value while accessing the checkbox.

// Traverse the datagrid to delete the accounts selected.
foreach( DataGridItem di in this.grdModelRights.Items )
{
for (int i=0; i < RoleIDs.Length; i++)
{
CheckBox cb = (CheckBox)di.FindControl("chkRightsID?" + RoleIDs[i]);
CheckBox statuscb = (CheckBox)di.FindControl("chkStatusID?" + RoleIDs[i]);
// Check if some account is selected than call the delete method.
if( cb !=null && cb.Checked )
{
Label lb = (Label)di.FindControl("hdnObjectID");
RolesData RolesDataObj = new RolesData();
RolesDataObj.Role_ID = int.Parse(RoleIDs[i]);
RolesDataObj.Object_ID = lb.Text.ToString();
RolesDataObj.Admin_Level = (int)Session["AdminLevel"];
RolesDataObj.ParentID = (int)Session["RoleID"];
RolesDataObj.Status_ID = 0;
if (statuscb !=null && statuscb.Checked)
{
RolesDataObj.Status_ID = 1;
}
RoleObj.GrantRight(RolesDataObj);
}
else
{
Label lb = (Label)di.FindControl("hdnObjectID");
RolesData RolesDataObj = new RolesData();
RolesDataObj.Role_ID = int.Parse(RoleIDs[i]);
RolesDataObj.Object_ID = lb.Text.ToString();
RolesDataObj.Admin_Level = (int)Session["AdminLevel"];
RolesDataObj.ParentID = (int)Session["RoleID"];
RoleObj.RevokeRight(RolesDataObj);
}// End of IF condition.
}
}// END of FOREACH loop.

Any help or any source code doing the same type of stuff will be highly appreciated.

Thanks in advance

WAK





Similar Threads
Thread Thread Starter Forum Replies Last Post
creating a checkbox column in a dataview badgolfer .NET Framework 2.0 0 April 27th, 2007 10:58 AM
rebinding checkbox checks in a template column texasraven ASP.NET 1.x and 2.0 Application Design 4 October 22nd, 2006 06:16 PM
saving checkbox state in template column texasraven ASP.NET 1.x and 2.0 Application Design 7 September 28th, 2005 01:18 PM
Checkbox Column ncminhtung BOOK: ASP.NET Website Programming Problem-Design-Solution 1 April 20th, 2005 07:08 AM
Adding Checkbox column in datagrid anita ASP.NET 1.0 and 1.1 Basics 0 December 20th, 2004 07:16 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.