Feb 07, 2012, 12:55 PM
Help! Set the value in the direct method of checkbox after dynamic create checkboxgroup.
I have create the checkbox of the checkboxgroup in the event Page_Init().
But I dont know how to set the checked value of the checkbox after I set the checkboxgroup's name value in the direct method.
My code is below.Pls help me.Many thanks.
But I dont know how to set the checked value of the checkbox after I set the checkboxgroup's name value in the direct method.
My code is below.Pls help me.Many thanks.
protected void Page_Init(object sender, EventArgs e)
{
ShowAuthorityList();
}
///add checkbox item to the CheckboxGroup in the panel.
protected void ShowAuthorityList()
{
var bb = Logistrics.DataAccess.AuthorityDir.Query(" ").OrderBy(x => x.AuthorityOrder);
List<AuthorityDir> ld = bb.ToList<AuthorityDir>();
int i = 0;
foreach (CheckboxGroup cbg in pnl.Items)
{
foreach (AuthorityDir ad in ld)
{
++i;
Ext.Net.Checkbox cb = new Ext.Net.Checkbox();
cb.BoxLabel = ad.AuthorityName;
cb.ID = ad.AuthorityID + ad.AuthorityTag + i.ToString();
cb.EnableViewState = false;
cb.Checked = false;
cb.Name = ad.AuthorityTag + "," + ad.AuthorityID;
cbg.Items.Add(cb);
}
cbg.Hidden = true;
}
}
///change the CheckboxGroup's name value in the combobox's select event.
protected void ShowAuthority(object sender, DirectEventArgs e)
{
if (cb_Menu.SelectedIndex >= 0)
{
var aa = Logistrics.DataAccess.Module.Query(" where ModuleTypeID ='" + cb_Menu.SelectedItem.Value + "'").OrderBy(x => x.ModuleOrder);
List<Module> lm = aa.ToList<Module>();
foreach (CheckboxGroup cbg in pnl.Items)
{
foreach (Module model in lm)
{
if (cbg.ID.Contains(model.ModuleTag))
{
cbg.FieldLabel = model.ModuleName;
cbg.Name = model.ModuleID;
cbg.EnableViewState = true;
cbg.Hidden = false;
}
}
//SetAuthorityList();
}
}
}
///set the value of the checkbox of the CheckboxGroup in the panel
protected void SetAuthorityList()
{
if (cb_Role.SelectedIndex >= 0)
{
foreach (CheckboxGroup cbg in pnl.Items)
{
var bb = Logistrics.DataAccess.RoleAuthorityList.Query(" where RoleID='" + cb_Role.SelectedItem.Value + "' and ModuleID='" + cbg.Name + "'");
List<RoleAuthorityList> lr = bb.ToList<RoleAuthorityList>();
foreach (RoleAuthorityList ra in lr)
{
foreach (Checkbox cb in cbg.Items)
{
if (cb.Name.Contains(ra.AuthorityTag))
{
cb.Checked = true;
}
}
}
}
}
}
///the aspx file code
<ext:ComboBox
ID="cb_Menu"
runat="server"
StoreID="Store2"
FieldLabel="Menu"
Editable="false"
AllowBlank="true"
DisplayField="ModuleTypeName"
ValueField="ModuleTypeID"
TypeAhead="true"
Mode="Local"
ForceSelection="true"
TriggerAction="All"
EmptyText="select one choice..."
Width="250"
>
<DirectEvents>
<Select OnEvent="ShowAuthority" Failure="Ext.MessageBox.alert('Load failed', 'Error during ajax event!');"/>
</DirectEvents>