When I put a Radgrid inside a regular asp:Menu and hit the Save button, Radgrid shows the number of items in the grid (see RadgridWorks code).
RadgridWorks.aspx:
RadgridWorks.aspx.cs:
RadgridFails.aspx:
RadgridFails.aspx.cs:
However, when I put a Radgrid inside a ASPxPageControl and hit the Save button, the btnSave_OnClick shows that the row count for the Radgrid is zero (see RadgridFails code).
What I'm trying to do is simply loop through the grid after checking/unchecking checkboxes and committing those values to the db. Incidentally, I get the same behavior with a regular asp:GridView. It works when inside an asp:Menu, but not when inside a ASPxPageControl. Any help is much appreciated!
RadgridWorks.aspx:
<
body
>
<
form
id
=
"form1"
runat
=
"server"
>
<
div
>
<
asp:Menu
ID
=
"menuScheduleActivityEditor"
Width
=
"350px"
runat
=
"server"
Orientation
=
"Horizontal"
OnMenuItemClick
=
"menuScheduleActivityEditor_MenuItemClick"
StaticEnableDefaultPopOutImage
=
"false"
Font-Bold
=
"True"
>
<
Items
>
<
asp:MenuItem
Text
=
"Checklist"
Value
=
"0"
Selected
=
"True"
></
asp:MenuItem
>
<
asp:MenuItem
Text
=
"Notes"
Value
=
"1"
></
asp:MenuItem
>
</
Items
>
</
asp:Menu
>
<
br
/>
<
asp:MultiView
ID
=
"multiviewScheduleActivityEditor"
runat
=
"server"
ActiveViewIndex
=
"0"
>
<
asp:View
ID
=
"viewDetails"
runat
=
"server"
>
<
asp:Button
ID
=
"btnSave"
runat
=
"server"
Text
=
"Save Checked Items"
OnClick
=
"btnSave_OnClick"
/>
<
br
/>
<
radG:RadGrid
ID
=
"rgChecklistItems"
AllowMultiRowSelection
=
"True"
runat
=
"server"
AllowSorting
=
"True"
GridLines
=
"None"
>
<
MasterTableView
AutoGenerateColumns
=
"False"
DataKeyNames
=
"ScheduleActivityChecklistItemID"
>
<
RowIndicatorColumn
Visible
=
"False"
>
<
HeaderStyle
Width
=
"20px"
></
HeaderStyle
>
</
RowIndicatorColumn
>
<
ExpandCollapseColumn
Visible
=
"False"
>
<
HeaderStyle
Width
=
"19px"
></
HeaderStyle
>
</
ExpandCollapseColumn
>
<
Columns
>
<
radG:GridTemplateColumn
HeaderText
=
"Complete"
UniqueName
=
"Complete"
>
<
ItemTemplate
>
<
asp:CheckBox
ID
=
"chboxComplete"
runat
=
"server"
Checked='<%# Bind("Complete") %>'
Enabled="true" />
</
ItemTemplate
>
<
EditItemTemplate
>
<
asp:CheckBox
ID
=
"chboxComplete"
runat
=
"server"
Checked='<%# Bind("Complete") %>' />
</
EditItemTemplate
>
</
radG:GridTemplateColumn
>
<
radG:GridBoundColumn
UniqueName
=
"ScheduleActivityChecklistName"
HeaderText
=
"Item"
DataField
=
"ScheduleActivityChecklistName"
>
<
ItemStyle
HorizontalAlign
=
"Left"
/>
</
radG:GridBoundColumn
>
<
radG:GridBoundColumn
UniqueName
=
"ScheduleActivityChecklistID"
HeaderText
=
"saCID"
DataField
=
"ScheduleActivityChecklistID"
>
<
ItemStyle
HorizontalAlign
=
"Left"
/>
</
radG:GridBoundColumn
>
<
radG:GridBoundColumn
UniqueName
=
"ChecklistID"
HeaderText
=
"CID"
DataField
=
"ChecklistID"
>
<
ItemStyle
HorizontalAlign
=
"Left"
/>
</
radG:GridBoundColumn
>
<
radG:GridBoundColumn
UniqueName
=
"ScheduleActivityChecklistItemID"
HeaderText
=
"saCIID"
DataField
=
"ScheduleActivityChecklistItemID"
>
<
ItemStyle
HorizontalAlign
=
"Left"
/>
</
radG:GridBoundColumn
>
</
Columns
>
<
PagerStyle
PagerTextFormat
=
"Pages: {4} | Displaying page {0} of {1}, items {2} to {3} of {5}."
Mode
=
"NumericPages"
/>
<
GroupHeaderItemStyle
BackColor
=
"LightSteelBlue"
/>
<
AlternatingItemStyle
BackColor
=
"#E0E0E0"
/>
<
ItemStyle
BackColor
=
"White"
/>
</
MasterTableView
>
<
ClientSettings
>
<
Selecting
AllowRowSelect
=
"True"
/>
</
ClientSettings
>
<
HeaderStyle
Wrap
=
"True"
HorizontalAlign
=
"Center"
VerticalAlign
=
"Middle"
/>
</
radG:RadGrid
>
</
asp:View
>
<
asp:View
ID
=
"viewNotes"
runat
=
"server"
>
NOTES
</
asp:View
>
</
asp:MultiView
>
</
div
>
</
form
>
</
body
>
RadgridWorks.aspx.cs:
public
partial
class
RadgridWorks : System.Web.UI.Page
{
protected
void
Page_Load(
object
sender, EventArgs e)
{
if
(!IsPostBack)
{
DoWork_ActivityDetail();
}
}
public
void
DoWork_ActivityDetail()
{
int
scheduleActivityID = 707;
string
signature =
"41aa56f1-a1c4-40c7-9f8c-97c262fc5a45"
;
// ---------------------------------------------
// CHECKLIST TAB
// ---------------------------------------------
rgChecklistItems.DataSource = GetScheduleActivityChecklistItems(signature, scheduleActivityID);
rgChecklistItems.DataBind();
int
ab = rgChecklistItems.Items.Count;
}
protected
void
btnSave_OnClick(
object
sender, EventArgs e)
{
string
signature =
"41aa56f1-a1c4-40c7-9f8c-97c262fc5a45"
;
string
portalUserID =
"ADMIN"
;
int
scheduleActivityID = 707;
bool
AutoComplete =
false
;
int
ab = rgChecklistItems.Items.Count;
int
bmt_ScheduleActivityChecklistID;
int
bmt_ChecklistID;
int
bmt_ScheduleActivityChecklistItemID;
string
bmt_ChecklistItemComplete =
"F"
;
foreach
(GridDataItem x
in
rgChecklistItems.Items)
{
bmt_ScheduleActivityChecklistID =
int
.Parse(x.Cells[4].Text);
bmt_ChecklistID =
int
.Parse(x.Cells[5].Text);
bmt_ScheduleActivityChecklistItemID =
int
.Parse(x.Cells[6].Text);
//Get the value of the row's checkbox
CheckBox chkbox1 = (CheckBox)x.FindControl(
"chboxComplete"
);
if
(AutoComplete ==
true
)
{
bmt_ChecklistItemComplete =
"T"
;
}
else
{
if
(chkbox1.Checked)
{
bmt_ChecklistItemComplete =
"T"
;
}
else
{
bmt_ChecklistItemComplete =
"F"
;
}
BmtSchedulingService.SchedulingService s =
new
BmtSchedulingService.SchedulingService();
BmtSchedulingService.BmtApiResult r =
null
;
r = s.UpdateScheduleActivityCheckListItem(signature, scheduleActivityID, bmt_ScheduleActivityChecklistID, bmt_ChecklistID, bmt_ScheduleActivityChecklistItemID, bmt_ChecklistItemComplete, portalUserID);
}
}
DoWork_ActivityDetail();
}
public
DataView GetScheduleActivityChecklistItems(
string
signature,
int
scheduleActivityID)
{
BmtSchedulingService.SchedulingService s =
new
BmtSchedulingService.SchedulingService();
BmtSchedulingService.ScheduleActivityChecklistItemData[] r =
null
;
r = s.GetScheduleActivityChecklistItems(signature, scheduleActivityID);
DataTable dt =
new
DataTable();
dt.Columns.Add(
"ScheduleActivityID"
,
typeof
(
int
));
dt.Columns.Add(
"ScheduleActivityChecklistID"
,
typeof
(
int
));
dt.Columns.Add(
"ChecklistID"
,
typeof
(
int
));
dt.Columns.Add(
"ScheduleActivityChecklistName"
,
typeof
(
string
));
dt.Columns.Add(
"ScheduleActivityChecklistItemName"
,
typeof
(
string
));
dt.Columns.Add(
"ScheduleActivityChecklistItemID"
,
typeof
(
string
));
dt.Columns.Add(
"ScheduleActivityChecklistItemCategory"
,
typeof
(
string
));
dt.Columns.Add(
"Complete"
,
typeof
(
bool
));
dt.Columns.Add(
"DateCompleted"
,
typeof
(
string
));
dt.Columns.Add(
"UserCompleted"
,
typeof
(
string
));
DataRow oDataRow;
for
(
int
i = 0; i < r.Length; i++)
{
oDataRow = dt.NewRow();
oDataRow[
"ScheduleActivityID"
] = r[i].ScheduleActivityID.ToString();
oDataRow[
"ScheduleActivityChecklistID"
] = r[i].ScheduleActivityChecklistID.ToString();
oDataRow[
"ChecklistID"
] = r[i].ChecklistID.ToString();
oDataRow[
"ScheduleActivityChecklistName"
] = r[i].ScheduleActivityChecklistName.ToString();
oDataRow[
"ScheduleActivityChecklistItemName"
] = r[i].ScheduleActivityChecklistItemName.ToString();
oDataRow[
"ScheduleActivityChecklistItemID"
] = r[i].ScheduleActivityChecklistItemID.ToString();
oDataRow[
"ScheduleActivityChecklistItemCategory"
] = r[i].ScheduleActivityChecklistItemCategory.ToString();
oDataRow[
"Complete"
] = r[i].Complete.ToString();
oDataRow[
"DateCompleted"
] = r[i].DateCompleted.ToString();
oDataRow[
"UserCompleted"
] = r[i].UserCompleted.ToString();
dt.Rows.Add(oDataRow);
}
return
dt.DefaultView;
}
protected
void
menuScheduleActivityEditor_MenuItemClick(
object
sender, MenuEventArgs e)
{
multiviewScheduleActivityEditor.ActiveViewIndex = Int32.Parse(e.Item.Value);
int
i;
for
(i = 0; i <= menuScheduleActivityEditor.Items.Count - 1; i++)
{
if
(i.ToString() == e.Item.Value)
{
menuScheduleActivityEditor.Items[i].Enabled =
false
;
}
else
{
menuScheduleActivityEditor.Items[i].Enabled =
true
;
}
}
}
}
RadgridFails.aspx:
<
body
>
<
form
id
=
"form1"
runat
=
"server"
>
<
div
>
<
dxtc:ASPxPageControl
ID
=
"pcActivityDetail"
runat
=
"server"
ActiveTabIndex
=
"0"
CssFilePath
=
"~/App_Themes/Aqua/{0}/styles.css"
CssPostfix
=
"Aqua"
Height
=
"297px"
ImageFolder
=
"~/App_Themes/Aqua/{0}/"
LoadingPanelText
=
""
TabSpacing
=
"3px"
Width
=
"826px"
EnableViewState
=
"False"
>
<
ContentStyle
>
<
Border
BorderColor
=
"#AECAF0"
BorderStyle
=
"Solid"
BorderWidth
=
"1px"
></
Border
>
</
ContentStyle
>
<
Paddings
Padding
=
"2px"
PaddingLeft
=
"5px"
PaddingRight
=
"5px"
></
Paddings
>
<
TabPages
>
<
dxtc:TabPage
Name
=
"tabChecklist"
Text
=
"Checklist"
>
<
ContentCollection
>
<
dxw:ContentControl
ID
=
"ContentControlChecklist"
runat
=
"server"
>
<
asp:Button
ID
=
"btnSave"
runat
=
"server"
Text
=
"Save Checked Items"
OnClick
=
"btnSave_OnClick"
/>
<
br
/>
<
br
/>
<
radG:RadGrid
ID
=
"rgChecklistItems"
AllowMultiRowSelection
=
"True"
runat
=
"server"
AllowSorting
=
"True"
GridLines
=
"None"
>
<
MasterTableView
AutoGenerateColumns
=
"False"
DataKeyNames
=
"ScheduleActivityChecklistItemID"
>
<
RowIndicatorColumn
Visible
=
"False"
>
<
HeaderStyle
Width
=
"20px"
></
HeaderStyle
>
</
RowIndicatorColumn
>
<
ExpandCollapseColumn
Visible
=
"False"
>
<
HeaderStyle
Width
=
"19px"
></
HeaderStyle
>
</
ExpandCollapseColumn
>
<
Columns
>
<
radG:GridTemplateColumn
HeaderText
=
"Complete"
UniqueName
=
"Complete"
>
<
ItemTemplate
>
<
asp:CheckBox
ID
=
"chboxComplete"
runat
=
"server"
Checked='<%# Bind("Complete") %>'
Enabled="true" />
</
ItemTemplate
>
<
EditItemTemplate
>
<
asp:CheckBox
ID
=
"chboxComplete"
runat
=
"server"
Checked='<%# Bind("Complete") %>' />
</
EditItemTemplate
>
</
radG:GridTemplateColumn
>
<
radG:GridBoundColumn
UniqueName
=
"ScheduleActivityChecklistName"
HeaderText
=
"Item"
DataField
=
"ScheduleActivityChecklistName"
>
<
ItemStyle
HorizontalAlign
=
"Left"
/>
</
radG:GridBoundColumn
>
<
radG:GridBoundColumn
UniqueName
=
"ScheduleActivityChecklistID"
HeaderText
=
"saCID"
DataField
=
"ScheduleActivityChecklistID"
>
<
ItemStyle
HorizontalAlign
=
"Left"
/>
</
radG:GridBoundColumn
>
<
radG:GridBoundColumn
UniqueName
=
"ChecklistID"
HeaderText
=
"CID"
DataField
=
"ChecklistID"
>
<
ItemStyle
HorizontalAlign
=
"Left"
/>
</
radG:GridBoundColumn
>
<
radG:GridBoundColumn
UniqueName
=
"ScheduleActivityChecklistItemID"
HeaderText
=
"saCIID"
DataField
=
"ScheduleActivityChecklistItemID"
>
<
ItemStyle
HorizontalAlign
=
"Left"
/>
</
radG:GridBoundColumn
>
</
Columns
>
<
PagerStyle
PagerTextFormat
=
"Pages: {4} | Displaying page {0} of {1}, items {2} to {3} of {5}."
Mode
=
"NumericPages"
/>
<
GroupHeaderItemStyle
BackColor
=
"LightSteelBlue"
/>
<
AlternatingItemStyle
BackColor
=
"#E0E0E0"
/>
<
ItemStyle
BackColor
=
"White"
/>
</
MasterTableView
>
<
ClientSettings
>
<
Selecting
AllowRowSelect
=
"True"
/>
</
ClientSettings
>
<
HeaderStyle
Wrap
=
"True"
HorizontalAlign
=
"Center"
VerticalAlign
=
"Middle"
/>
</
radG:RadGrid
>
</
dxw:ContentControl
>
</
ContentCollection
>
</
dxtc:TabPage
>
<
dxtc:TabPage
Name
=
"tabNotes"
Text
=
"Notes"
>
<
ContentCollection
>
<
dxw:ContentControl
ID
=
"ContentControlNotes"
runat
=
"server"
>
NOTES
</
dxw:ContentControl
>
</
ContentCollection
>
</
dxtc:TabPage
>
</
TabPages
>
</
dxtc:ASPxPageControl
>
</
div
>
</
form
>
</
body
>
RadgridFails.aspx.cs:
public
partial
class
RadgridFails : System.Web.UI.Page
{
protected
void
Page_Load(
object
sender, EventArgs e)
{
if
(!IsPostBack)
{
DoWork_ActivityDetail();
}
}
public
void
DoWork_ActivityDetail()
{
int
scheduleActivityID = 707;
string
signature =
"41aa56f1-a1c4-40c7-9f8c-97c262fc5a45"
;
// ---------------------------------------------
// CHECKLIST TAB
// ---------------------------------------------
rgChecklistItems.DataSource = GetScheduleActivityChecklistItems(signature, scheduleActivityID);
rgChecklistItems.DataBind();
// THIS RETURNS THE NUMBER OF ITEMS AND WORKS FINE !!!
int
ab = rgChecklistItems.Items.Count;
}
protected
void
btnSave_OnClick(
object
sender, EventArgs e)
{
string
signature =
"41aa56f1-a1c4-40c7-9f8c-97c262fc5a45"
;
string
portalUserID =
"ADMIN"
;
int
scheduleActivityID = 707;
bool
AutoComplete =
false
;
// AT THIS POINT, NUMBER OF ITEMS = 0 EVEN THOUGH THE GRID SHOWED ITEMS WHEN LOADING !!!!!
int
ab = rgChecklistItems.Items.Count;
int
bmt_ScheduleActivityChecklistID;
int
bmt_ChecklistID;
int
bmt_ScheduleActivityChecklistItemID;
string
bmt_ChecklistItemComplete =
"F"
;
foreach
(GridDataItem x
in
rgChecklistItems.Items)
{
bmt_ScheduleActivityChecklistID =
int
.Parse(x.Cells[4].Text);
bmt_ChecklistID =
int
.Parse(x.Cells[5].Text);
bmt_ScheduleActivityChecklistItemID =
int
.Parse(x.Cells[6].Text);
//Get the value of the row's checkbox
CheckBox chkbox1 = (CheckBox)x.FindControl(
"chboxComplete"
);
if
(AutoComplete ==
true
)
{
bmt_ChecklistItemComplete =
"T"
;
}
else
{
if
(chkbox1.Checked)
{
bmt_ChecklistItemComplete =
"T"
;
}
else
{
bmt_ChecklistItemComplete =
"F"
;
}
BmtSchedulingService.SchedulingService s =
new
BmtSchedulingService.SchedulingService();
BmtSchedulingService.BmtApiResult r =
null
;
r = s.UpdateScheduleActivityCheckListItem(signature, scheduleActivityID, bmt_ScheduleActivityChecklistID, bmt_ChecklistID, bmt_ScheduleActivityChecklistItemID, bmt_ChecklistItemComplete, portalUserID);
}
}
DoWork_ActivityDetail();
}
public
DataView GetScheduleActivityChecklistItems(
string
signature,
int
scheduleActivityID)
{
BmtSchedulingService.SchedulingService s =
new
BmtSchedulingService.SchedulingService();
BmtSchedulingService.ScheduleActivityChecklistItemData[] r =
null
;
r = s.GetScheduleActivityChecklistItems(signature, scheduleActivityID);
DataTable dt =
new
DataTable();
dt.Columns.Add(
"ScheduleActivityID"
,
typeof
(
int
));
dt.Columns.Add(
"ScheduleActivityChecklistID"
,
typeof
(
int
));
dt.Columns.Add(
"ChecklistID"
,
typeof
(
int
));
dt.Columns.Add(
"ScheduleActivityChecklistName"
,
typeof
(
string
));
dt.Columns.Add(
"ScheduleActivityChecklistItemName"
,
typeof
(
string
));
dt.Columns.Add(
"ScheduleActivityChecklistItemID"
,
typeof
(
string
));
dt.Columns.Add(
"ScheduleActivityChecklistItemCategory"
,
typeof
(
string
));
dt.Columns.Add(
"Complete"
,
typeof
(
bool
));
dt.Columns.Add(
"DateCompleted"
,
typeof
(
string
));
dt.Columns.Add(
"UserCompleted"
,
typeof
(
string
));
DataRow oDataRow;
for
(
int
i = 0; i < r.Length; i++)
{
oDataRow = dt.NewRow();
oDataRow[
"ScheduleActivityID"
] = r[i].ScheduleActivityID.ToString();
oDataRow[
"ScheduleActivityChecklistID"
] = r[i].ScheduleActivityChecklistID.ToString();
oDataRow[
"ChecklistID"
] = r[i].ChecklistID.ToString();
oDataRow[
"ScheduleActivityChecklistName"
] = r[i].ScheduleActivityChecklistName.ToString();
oDataRow[
"ScheduleActivityChecklistItemName"
] = r[i].ScheduleActivityChecklistItemName.ToString();
oDataRow[
"ScheduleActivityChecklistItemID"
] = r[i].ScheduleActivityChecklistItemID.ToString();
oDataRow[
"ScheduleActivityChecklistItemCategory"
] = r[i].ScheduleActivityChecklistItemCategory.ToString();
oDataRow[
"Complete"
] = r[i].Complete.ToString();
oDataRow[
"DateCompleted"
] = r[i].DateCompleted.ToString();
oDataRow[
"UserCompleted"
] = r[i].UserCompleted.ToString();
dt.Rows.Add(oDataRow);
}
return
dt.DefaultView;
}
}