We currently have an admin page that allows us to search for customers by email. My task is to also implement functionality that allows us to see all of a particular customer's orders for the past two weeks when we make that search. I modeled this data binding after the current data binding that exists, but it just causes a stack overflow exception, and I'm not sure what I'm doing wrong. Here's the markup:
<
telerik:RadGrid
ID
=
"MailingsGrid"
runat
=
"server"
AllowSorting
=
"True"
CellSpacing
=
"0"
GridLines
=
"None"
PageSize
=
"50"
OnItemDataBound
=
"MailingsGrid_ItemDataBound"
>
<
MasterTableView
Width
=
"100%"
NoMasterRecordsText
=
"No users found"
AutoGenerateColumns
=
"false"
>
<
Columns
>
<
telerik:GridBoundColumn
DataField
=
"Sub_Order_ID"
HeaderText
=
"Sub_Order_ID"
UniqueName
=
"Sub_Order_ID"
ReadOnly
=
"true"
DataType
=
"System.Int32"
FilterControlAltText
=
"Filter Sub_Order_ID column"
SortExpression
=
"Sub_Order_ID"
/>
<
telerik:GridBoundColumn
DataField
=
"Num_Pages"
HeaderText
=
"Num_Pages"
UniqueName
=
"Num_Pages"
ReadOnly
=
"true"
DataType
=
"System.Int32"
FilterControlAltText
=
"Filter Num_Pages column"
SortExpression
=
"Num_Pages"
/>
<
telerik:GridTemplateColumn
SortExpression
=
"Address_1"
HeaderText
=
"Recipient"
HeaderButtonType
=
"TextButton"
GroupByExpression
=
"Address_1 Group by Address_1"
HeaderStyle-HorizontalAlign
=
"Left"
ItemStyle-HorizontalAlign
=
"Left"
ReadOnly
=
"true"
ItemStyle-Wrap
=
"false"
>
<
ItemTemplate
><%#MailALetter.Common.FormatAddressTo(DataBinder.Eval(Container, "DataItem.Title"), DataBinder.Eval(Container, "DataItem.Name"), DataBinder.Eval(Container, "DataItem.JobTitle"), DataBinder.Eval(Container, "DataItem.Company"), DataBinder.Eval(Container, "DataItem.Address_1"), DataBinder.Eval(Container, "DataItem.Address_2"), DataBinder.Eval(Container, "DataItem.Address_3"), DataBinder.Eval(Container, "DataItem.City"), DataBinder.Eval(Container, "DataItem.State"), DataBinder.Eval(Container, "DataItem.Zip_Code_5"), DataBinder.Eval(Container, "DataItem.Zip_Code_4"), DataBinder.Eval(Container, "DataItem.Country"))%>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridBoundColumn
DataField
=
"Date_Created"
DataType
=
"System.DateTime"
FilterControlAltText
=
"Filter Date_Created column"
HeaderText
=
"Date_Created"
ReadOnly
=
"True"
SortExpression
=
"Date_Created"
UniqueName
=
"Date_Created"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"Date_Fullfilled"
DataType
=
"System.DateTime"
FilterControlAltText
=
"Filter Date_Fullfilled column"
HeaderText
=
"Date_Fullfilled"
ReadOnly
=
"True"
SortExpression
=
"Date_Fullfilled"
UniqueName
=
"Date_Fullfilled"
>
</
telerik:GridBoundColumn
>
</
Columns
>
</
MasterTableView
>
</
telerik:RadGrid
>
And here's the code behind:
protected void SearchButton_Click(object sender, EventArgs e)
{
string EmailSearchTerm = SearchText.Text;
UserResults = DBContext.Users.Where(x => SqlMethods.Like(x.Email, "%" + EmailSearchTerm + "%")).ToList();
MembershipResults = DBContext.Memberships.Where(x => UserResults.Select(y => y.UserId).Contains(x.UserId)).ToList();
SearchResults.DataSource = UserResults;
// This line is causing the overflow exception
MailingsGrid.DataSource = DBContext.LetterReports.Where(x => x.UserID.Equals(MembershipResults[0].UserId)).ToList();
SearchResults.Rebind();
MailingsGrid.DataBind();
}
protected void MailingsGrid_ItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item is GridDataItem)
{
GridDataItem item = (GridDataItem)e.Item;
string SubOrderId = item.GetDataKeyValue("Sub_Order_ID").ToString();
string DateCreated = item.GetDataKeyValue("Date_Created").ToString();
string DateFullfilled = item.GetDataKeyValue("Date_Fulfilled").ToString();
string Pages = item.GetDataKeyValue("Num_Pages").ToString();
}
}
Any help would be greatly appreciated, this is the latest of many iterations, and I'm kind of at a loss at this point.