I have a checkbox in commanitem template.
I display the checkbox based on some values in the database and change the text of the checkbox accordingly.
On the first page load, my checkbox does not retain the values i set in the prerender event. After i do some postback (via the button in the itemtemplate) it displays the checkbox correctly. I set the grid in edit mode in my pre render event.
below is my code:
I display the checkbox based on some values in the database and change the text of the checkbox accordingly.
On the first page load, my checkbox does not retain the values i set in the prerender event. After i do some postback (via the button in the itemtemplate) it displays the checkbox correctly. I set the grid in edit mode in my pre render event.
below is my code:
protected void rgFunds_PreRender(object source, EventArgs e)
{
Button btnPostTransaction = (Button)rgFunds.MasterTableView.GetItems(GridItemType.CommandItem)[0].FindControl("btnPostTransaction");
CheckBox chkAutoRebalance = (CheckBox)rgFunds.MasterTableView.GetItems(GridItemType.CommandItem)[0].FindControl("chkAutoRebalance");
//Puts the grid in editmode
if (!IsPostBack)
{
foreach (GridItem item in rgFunds.MasterTableView.Items)
{
if (item is GridEditableItem)
{
GridEditableItem editableItem = item as GridDataItem;
editableItem.Edit = true;
}
}
rgFunds.Rebind();
}
//Set the AutoRebalance flag
foreach (GridDataItem item in rgFunds.Items)
{
HtmlInputHidden _fundID = (HtmlInputHidden)item.FindControl("_fundID");
int OnOff = Int32.Parse(_fundID.Value);
chkAutoRebalance.Checked = OnOff == 1 ? true : false;
}
// Get the AutoRebalancing flag from plan settings
if (ShowPostTransactionButton && IsCurrentEmployee && _allocationType == FundAllocation.AllocationType.Rebalance)
{
DataTable dtAutoRebalanceFrequency = FundRebalance.GetAutoRebalanceFrequencyByPlan(base.PlanID, DateTime.Now);
if (dtAutoRebalanceFrequency.Rows.Count > 0)
{
AutoRebalanceFrequency = dtAutoRebalanceFrequency.Rows[0][FundRebalance.Fields.RebalanceFrequency].ToString();
if (dtAutoRebalanceFrequency.Rows[0][FundRebalance.Fields.RebalanceFrequencyID].ToString() == ((int)FundRebalance.AutoRebalanceFrequency.NotAllowed).ToString())
{
chkAutoRebalance.Visible = false;
chkAutoRebalance.Checked = false;
}
else
{
chkAutoRebalance.Visible = true;
chkAutoRebalance.Text = "Auto Rebalance (" + AutoRebalanceFrequency + ")";
}
}
else
{
chkAutoRebalance.Visible = false;
chkAutoRebalance.Checked = false;
}
}
}
Grid declaration:
<
telerik:RadGrid
ID
=
"rgFunds"
runat
=
"server"
AllowSorting
=
"False"
EnableViewState
=
"false"
GridLines
=
"Both"
AllowMultiRowEdit
=
"true"
OnPreRender
=
"rgFunds_PreRender"
OnItemDataBound
=
"rgFunds_ItemDataBound"
OnItemCommand
=
"rgFunds_ItemCommand"
OnNeedDataSource
=
"rgFunds_NeedDataSource"
>
<
MasterTableView
TableLayout
=
"Fixed"
HierarchyDefaultExpanded
=
"true"
CommandItemDisplay
=
"Bottom"
EditMode
=
"InPlace"
EnableNoRecordsTemplate
=
"true"
>
<
CommandItemTemplate
>
<
table
width
=
"100%"
>
<
tr
>
<
td
colspan
=
"4"
align
=
"left"
>
<
asp:CheckBox
ID
=
"chkAutoRebalance"
runat
=
"server"
Visible
=
"true"
ForeColor
=
"White"
OnCheckedChanged
=
"chkAutoRebalance_CheckedChanged"
/>
</
td
>
<
td
align
=
"right"
>
<
asp:Button
ID
=
"btnPostTransaction"
runat
=
"server"
Text
=
"Post Transaction"
CssClass
=
"button"
CommandName
=
"PostTransaction"
/>
</
td
>
</
tr
>
</
table
>
</
CommandItemTemplate
>
<
Columns
>
<
telerik:GridTemplateColumn
ItemStyle-HorizontalAlign
=
"Left"
HeaderStyle-HorizontalAlign
=
"Left"
FooterStyle-HorizontalAlign
=
"Left"
UniqueName
=
"InvestmentOptions"
ReadOnly
=
"true"
HeaderText
=
"Investment Options"
>
<
ItemTemplate
>
<
asp:Label
ID
=
"_fundName"
runat
=
"server"
Text='<%# Eval("fundName")%>'></
asp:Label
>
<
asp:CheckBox
ID
=
"_excludeFund"
runat
=
"server"
Checked='<%# Eval("allowRebalanceExclude")%>'
Text="Exclude?" Visible='<%# Eval("allowRebalanceExclude")%>' />
<
input
type
=
"hidden"
id
=
"_fundID"
runat
=
"server"
/>
<
input
type
=
"hidden"
id
=
"_autoRebalanceFlag"
runat
=
"server"
/>
<
input
type
=
"hidden"
id
=
"_allowRebalance"
runat
=
"server"
/>
</
ItemTemplate
>
<
FooterTemplate
>
<
strong
>Total must equal 100%</
strong
></
FooterTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridTemplateColumn
ItemStyle-HorizontalAlign
=
"Right"
HeaderText
=
"Current %"
HeaderStyle-Width
=
"25%"
ReadOnly
=
"true"
DataField
=
"currentPercent"
UniqueName
=
"currentPercent"
>
<
ItemTemplate
>
<
asp:Label
ID
=
"_currentPercent"
runat
=
"server"
Text='<%# Eval("currentPercent", "{0:N2}%")%>'>
</
asp:Label
></
ItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridTemplateColumn
ItemStyle-HorizontalAlign
=
"Right"
UniqueName
=
"futurePercent"
HeaderStyle-Width
=
"25%"
HeaderText
=
"New %"
>
<
ItemTemplate
>
<
asp:Label
ID
=
"_futurePercent"
runat
=
"server"
Text='<%# Eval("futurePercent", "{0:N2}%")%>'></
asp:Label
>
</
ItemTemplate
>
<
EditItemTemplate
>
<
asp:TextBox
ID
=
"txtNewPercent"
runat
=
"server"
CssClass
=
"percent"
groupName
=
"allocations"
Width
=
"40px"
onchange
=
"SumGroup(this, false)"
Text='<%# Eval("futurePercent")%>' />
%
<
asp:RangeValidator
ID
=
"newPercentageRange"
runat
=
"server"
ControlToValidate
=
"txtNewPercent"
Type
=
"Integer"
CssClass
=
"errormessagesmall"
Display
=
"None"
/>
<
asp:CustomValidator
ID
=
"newPercentageIncrement"
runat
=
"server"
ControlToValidate
=
"txtNewPercent"
ClientValidationFunction
=
"Mod_ClientValidate"
CssClass
=
"errormessagesmall"
Display
=
"None"
/>
<
cc1:ValidatorCalloutExtender
ID
=
"newPercentageRangeCallout"
runat
=
"server"
TargetControlID
=
"newPercentageRange"
Width
=
"235px"
/>
<
cc1:ValidatorCalloutExtender
ID
=
"newPercentageIncrementCallout"
runat
=
"server"
TargetControlID
=
"newPercentageIncrement"
Width
=
"235px"
/>
</
EditItemTemplate
>
<
FooterTemplate
>
<
asp:TextBox
ID
=
"fundTotal"
runat
=
"server"
CssClass
=
"percent"
onfocus
=
"blur()"
Enabled
=
"false"
Font-Bold
=
"true"
ForeColor
=
"Black"
Width
=
"40px"
/>
%
<
asp:CompareValidator
ID
=
"totalEqual100"
runat
=
"server"
ControlToValidate
=
"fundTotal"
ValueToCompare
=
"100"
Operator
=
"Equal"
CssClass
=
"errormessagesmall"
Display
=
"None"
ErrorMessage
=
"New allocations must total 100%."
/>
<
asp:RequiredFieldValidator
ID
=
"fundTotalRequired"
runat
=
"server"
ControlToValidate
=
"fundTotal"
Display
=
"None"
Visible
=
"false"
ErrorMessage="You <em>must</
em
> enter an allocation." />
<
cc1:ValidatorCalloutExtender
ID
=
"fundTotalRequiredCallout"
runat
=
"server"
TargetControlID
=
"fundTotalRequired"
Width
=
"235px"
/>
<
cc1:ValidatorCalloutExtender
ID
=
"totalEqual100Callout"
runat
=
"server"
TargetControlID
=
"totalEqual100"
Width
=
"235px"
/>
</
FooterTemplate
>
</
telerik:GridTemplateColumn
>
</
Columns
>
</
MasterTableView
>
</
telerik:RadGrid
>