Can anyone help me to make a nested repeater. I use C# (.asp 2.0) and MySQL database. (SORRY IF MY ENGLISH AN'T GOOD. Live in Denmark)
I have try to find something on the internet but i can get it right so it works whit MySQL only with MSSQL i can get it to work.
Expand|Select|Wrap|Line Numbers
- <asp:Repeater ID="CategoryList" runat="server" EnableViewState="False">
- <ItemTemplate>
- <h4><%# Eval("Titel") %></h4>
- <p><%# Eval("Textarea") %></p>
- <asp:Repeater runat="server" ID="ProductsByCategoryList" EnableViewState="False"
- DataSource='<%# GetProductsInCategory((int) Eval("BrugerID")) %>'>
- <HeaderTemplate>
- <ul>
- </HeaderTemplate>
- <ItemTemplate>
- <li><strong><%# Eval("Brugernavn") %></strong></li>
- </ItemTemplate>
- <FooterTemplate>
- </ul>
- </FooterTemplate>
- </asp:Repeater>
- </ItemTemplate>
- </asp:Repeater>
And my C# code. (It is the last i can't translate)
Expand|Select|Wrap|Line Numbers
- using System;
- using System.Data;
- using System.Configuration;
- using System.Collections;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- using System.Web.UI.HtmlControls;
- using MySql.Data.MySqlClient;
- public partial class NestedRepeater : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- string strConnectionString = ConfigurationManager.ConnectionStrings["SqlConnectionString"].ConnectionString;
- MySqlConnection conn = new MySqlConnection(strConnectionString);
- MySqlCommand command = conn.CreateCommand();
- command.CommandText = "select * from lovemusicDebat WHERE id=?id;";
- command.Parameters.Add("?id", MySqlDbType.Int16, 16).Value = User.Identity.Name;
- conn.Open();
- CategoryList.DataSource = command.ExecuteReader();
- CategoryList.DataBind();
- conn.Close();
- }
- private Northwind.ProductsDataTable allProducts = null;
- protected Northwind.ProductsDataTable GetProductsInCategory(int categoryID)
- {
- if (allProducts == null)
- {
- ProductsBLL productAPI = new ProductsBLL();
- allProducts = productAPI.GetProducts();
- }
- allProducts.DefaultView.RowFilter = "id = " + categoryID;
- return allProducts;
- }
- }