[C#/.NET/RadGrid] Binding data to a table

Background: The admin section of our page allows us to search for a specific user and display their basic info. Underneath that table, we have a few tabs that allow us to change that info. My task is to implement a tab that lists all of their orders for the past two weeks. I’m trying to model the data binding on the code that’s already there for finding a user by email.

Code: Admin.aspx

<telerik:RadPageView ID="pvMailings" runat="server" TabIndex="3"> <telerik:RadGrid ID="MailingsGrid" runat="server" AllowSorting="True" AllowPaging="True" CellSpacing="0" GridLines="None" PageSize="50" OnNeedDataSource="SearchButton_Click"> <MasterTableView Width="100%" NoMasterRecordsText="No users found" DataKeyNames="Sub_Order_ID,Date_Created,Date_Fullfilled,Num_Pages" AutoGenerateColumns="false"> <Columns> <telerik:GridBoundColumn DataField="Sub_Order_Id" HeaderText="Mailing #" UniqueName="Sub_Order_Id" ReadOnly="true" /> <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" HeaderText="Created On" UniqueName="CreatedOn" ReadOnly="true" /> <telerik:GridBoundColumn DataField="Date_Fullfilled" HeaderText="Mailed On" UniqueName="MailedOn" ReadOnly="true" /> <telerik:GridBoundColumn DataField="Num_Pages" HeaderText="Pages" UniqueName="Pages" ReadOnly="true" /> </Columns> </MasterTableView> </telerik:RadGrid> </telerik:RadPageView> 

Admin.aspx.cs

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(); } 

Whenever I debug this, I get a stack overflow exception. This is the latest iteration of this code, and I am really stuck, any ideas out there?

submitted by /u/PMDevS
[link] [comments]

Leave a Reply