I've looked at a lot of similar questions here, but to no avail.
So here goes...
I'm creating a set of user controls that display a list of grid-like tables. Anyway, the objective is to list the grids, mess with the each grids data (client-side) and press save. The grids work great, but when I press save teh repeater in the VIEWER is always empty. Any help appreciated!
The Basic Layout Goes Like This
- PAGE
- ...updatePANEL
- ......usercontrolVIEWER
- .........saveBUTTON
- .........repeaterCONTROL
- ............usercontrolGRID
- ............usercontrolGRID
- ............ETC!
The PAGE Looks Like This
<asp:Content ID="Content2" ContentPlaceHolderID="body" runat="server">
<asp:UpdatePanel id="udPanel" UpdateMode="Always" runat="server">
<Triggers>
</Triggers>
<ContentTemplate>
<uc:CommitImporterView ID="civData" runat="server" />
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>
public partial class CommitsAndActualsImporter : BaseForm
{
#region EVENTS
protected void Page_Init(object sender, EventArgs e)
{
setUpEventHandlers();
if (!IsPostBack)
initalize();
}
protected void Page_Load(object sender, EventArgs e)
{
}
protected void myListOfGroups_DataBinding(object sender, EventArgs e)
{
//.. Code to bind the list goes here ...
myListOfGroups.SelectedIndex = setSelectedIndex(collection);
}
protected void myListOfGroups_SelectedIndexChanged(object sender, EventArgs e)
{
myGroup = myListOfGroups.Find(selectedItem => selectedItem.Key == key);
dataSource = buildViewDataSource(base.ProjectKey, base.AsOf, myGroup.FcrGroupKey, myGroup.ContractorKey, myGroup.WbsKey);
civData.AsOf = base.AsOf;
civData.ProjectKey = base.ProjectKey;
civData.DataSource = dataSource;
civData.DataBind();
}
#endregion
#region METHODS
private void initalize()
{
ContractorInviteItems dataSource = listGroups(ProjectKey, AsOf);
myListOfGroups.DataSource = dataSource;
myListOfGroups.DataBind();
}
private void setUpEvents()
{
myListOfGroups.DataBinding += new EventHandler(myListOfGroups_DataBinding);
myListOfGroups.SelectedIndexChanged += new EventHandler(myListOfGroups_SelectedIndexChanged);
}
#endregion
}
The VIEWER User Control Looks Like This
<%@ Register Src="~/UserControls/CommitImporterGrid.ascx" TagName="CommitImporterGrid" TagPrefix="uc" %>
<asp:Button ID="btnSave" runat="server" Text="Save" />
<asp:HiddenField ID="hidAsOf" runat="server" Value="" />
<asp:HiddenField ID="hidProjectKey" runat="server" Value="0" />
<asp:Repeater ID="repCommitImporterView" runat="server">
<ItemTemplate>
<uc:CommitImporterGrid runat="server" />
</ItemTemplate>
</asp:Repeater>
public partial class CommitImporterView : System.Web.UI.UserControl
{
#region PROPERTIES & FIELDS
private enum basisUsed
{
Dollars,
Hours,
IsInvalid
}
public Object DataSource { get; set; }
public DateTime AsOf { get { return Convert.ToDateTime(hidAsOf.Value); } set { hidAsOf.Value = value.ToString(); } }
public Int32 ProjectKey { get { return Convert.ToInt32(hidProjectKey.Value); } set { hidProjectKey.Value = value.ToString(); } }
#endregion
#region EVENTS
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
setupEvents();
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
this.DataBind();
}
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
}
public override void DataBind()
{
base.DataBind();
}
protected void btnSave_Click(object sender, EventArgs e)
{
Int32 count = repCommitImporterView.Controls.Count;
foreach (Control control in repCommitImporterView.Controls)
{
if (control is UserControls.CommitImporterGrid)
{
string stop = "";
}
}
}
protected void repCommitImporterView_DataBinding(object sender, EventArgs e)
{
if (DataSource == null)
return;
if (!IsPostBack)
{
Decimal totalSummaryCbudDollars = 0;
Decimal totalSummaryCbudHours = 0;
if (summaryValuesExist(out totalSummaryCbudDollars, out totalSummaryCbudHours))
alignSummarizedRecords(totalSummaryCbudDollars, totalSummaryCbudHours);
repCommitImporterView.DataSource = DataSource;
}
}
protected void repCommitImporterView_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
ContractorInviteCommitsAndActualsImport record = (ContractorInviteCommitsAndActualsImport)e.Item.DataItem;
CommitImporterGrid grid = new CommitImporterGrid();
grid = (UserControls.CommitImporterGrid)Page.LoadControl("~/UserControls/CommitImporterGrid.ascx") as UserControls.CommitImporterGrid;
grid.AsOf = this.AsOf;
grid.ProjectKey = this.ProjectKey;
grid.DataSource = getDataSource(record);
grid.DataBind();
repCommitImporterView.Controls.Add(grid);
}
#endregion
#region METHODS
private void setupEvents()
{
btnSave.Click += new EventHandler(btnSave_Click);
repCommitImporterView.DataBinding += new EventHandler(repCommitImporterView_DataBinding);
repCommitImporterView.ItemDataBound += new RepeaterItemEventHandler(repCommitImporterView_ItemDataBound);
}
#endregion
}
The GRID User Control Lokks Like