Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASP: Repeater Problem

Status
Not open for further replies.

dhedden

Programmer
Jul 16, 2005
8
US
I have the code:

<asp:SqlDataSource runat="server" ID="Reunion_Display" ConnectionString="<%$ ConnectionStrings:SqlServer %>" SelectCommand ="SELECT Graduating_Class_ID, Reunion_Date, Reunion_Details, Contact_Name, Contact_Email, Contact_URL, Contact_Phone, Class_Notes FROM Reunion_Display">
</asp:SqlDataSource>
<asp:Repeater ID="ReunionDis" runat="server" DataSourceID="Reunion_Display">
<HeaderTemplate>
<table>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><h2>Class of <%#Container.DataItem("Graduating_Class_ID")%></h2>
</td>
</tr>
<tr>
<td><div style="Padding-left: 10px"><i><%#Container.DataItem("Class_Notes")%></i></div>
</td>
</tr>
<tr>
<td><div style="Padding-left: 10px"><b><%#Container.DataItem("Reunion_Date")%></b></div>
</td>
</tr>
<tr>
<td><div style="Padding-left: 20px"><%#Container.DataItem("Reunion_Details")%></div>
</td>
</tr>
<tr>
<td><div style="Padding-left: 20px">Contact <%#Container.DataItem("Contact_Name")%> for more info.</div>
</td>
</tr>
<tr>
<td><div style="Padding-left: 20px"><a href="mailto:<%#Container.DataItem("Contact_Email")%>"><%#Container.DataItem("Contact_Email")%></a></div>
</td>
</tr>
<tr>
<td><div style="Padding-left: 20px"><a href="<%#Container.DataItem("Contact_URL")%>"><%#Container.DataItem("Contact_URL")%></a></div>
</td>
</tr>
<tr>
<td><%#Container.DataItem("Contact_Phone")%>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table> >
</FooterTemplate>
</asp:Repeater>

In the view, there are multiple records with the same content.
ex) Graduating_Class_ID Class_Notes
1948 7/8/2006
1948 Marriott at 5p.m.

How do I make it so only on of the Graduating_Glass_ID numbers shows up?

What Shows:

1948
7/8/2006

1948
Marriott at 5p.m.


Needs to Show:

1948
7/8/2006
Marriott at 5p.m.

 
This isn't a repeater problem. You need to rethink displaying the instances there are multiple records.

One solution would be to nest a DataRepeater in the <td> cell that you currently have <%#Container.DataItem("Class_Notes")%>. Run a query to bring up the records of Class_Notes with an id of 1948, for example, and then display all the notes that way.

 
How do you nest a DataRepeater. I am new to ASP.Net
 
Would you be able to walk me through the process?
 
My example here uses DataLists and DataGrids, but you can use DataRepeaters,DataLists, and DataGrid interchangeablely depending on what you need to display. I'd go with something simple like I suggested above, A DataRepeater in a DataRepeater. I think this will get you started.

HTML Code
Code:
<asp:DataList Runat="server" ID="dtAccessories" OnItemDataBound="BindAccessoryGrid" Width="640">

      <ItemTemplate>

            <tr>

                  <td valign="top">

                        <br />

 

                              I put a DataGrid here, put your control here

                              <asp:DataGrid id="dgAccessories" runat="server" ShowFooter="False" ShowHeader="True" AutoGenerateColumns="False"

                                                                  Width="500" CellPadding="3">

                                    <Columns>

                                                                        

                                    </Columns>

                              </asp:DataGrid>

                  </td>

            </tr>

      </ItemTemplate>

</asp:DataList>









Code Behind

Code:
            public void BindAccessoryGrid(object sender, DataListItemEventArgs e)

            {

                  string sKey;

                  // see what type of row (header, footer, item, etc.) caused the event

                  if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)

                  {

 

                        DatabaseFunctions handle = new DatabaseFunctions();

 

                        System.Web.UI.WebControls.Label oLabel;

                        oLabel = ((System.Web.UI.WebControls.Label)(e.Item.FindControl("lblPhoneID")));

 

                        sKey = oLabel.Text;

 

                        

                        // Get reference to datagrid control in this row

 

                        System.Web.UI.WebControls.DataGrid oGrid;

                        oGrid = ((System.Web.UI.WebControls.DataGrid)(e.Item.FindControl("dgAccessories")));

 

                        iSiteID = Convert.ToInt32(Request.Cookies["SiteID"].Value);             

                        iCarrierID = handle.GetCarrierID(Convert.ToString(Request.Cookies["CartID"].Value));

 

                        DataSet ds = handle.GetPhoneAccessories(iSiteID, iCarrierID, Convert.ToInt32(sKey));

 

                        oGrid.DataSource = ds;

                        oGrid.DataBind();

 

                  }

 

            }

Let me know if you need further help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top