473,320 Members | 2,147 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Nested Repeater with MySQL (WEB, C#)

Hi..

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
  1. <asp:Repeater ID="CategoryList" runat="server" EnableViewState="False">
  2.             <ItemTemplate>
  3.                 <h4><%# Eval("Titel") %></h4>
  4.                 <p><%# Eval("Textarea") %></p>
  5.                 <asp:Repeater runat="server" ID="ProductsByCategoryList" EnableViewState="False"
  6.                         DataSource='<%# GetProductsInCategory((int) Eval("BrugerID")) %>'>
  7.                     <HeaderTemplate>
  8.                         <ul>
  9.                     </HeaderTemplate>
  10.                     <ItemTemplate>
  11.                         <li><strong><%# Eval("Brugernavn") %></strong></li>
  12.                     </ItemTemplate>
  13.                     <FooterTemplate>
  14.                         </ul>
  15.                     </FooterTemplate>
  16.                 </asp:Repeater>    
  17.             </ItemTemplate>
  18.         </asp:Repeater>

And my C# code. (It is the last i can't translate)

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Data;
  3. using System.Configuration;
  4. using System.Collections;
  5. using System.Web;
  6. using System.Web.Security;
  7. using System.Web.UI;
  8. using System.Web.UI.WebControls;
  9. using System.Web.UI.WebControls.WebParts;
  10. using System.Web.UI.HtmlControls;
  11. using MySql.Data.MySqlClient;
  12.  
  13. public partial class NestedRepeater : System.Web.UI.Page
  14. {
  15.     protected void Page_Load(object sender, EventArgs e)
  16.     {
  17.  
  18.         string strConnectionString = ConfigurationManager.ConnectionStrings["SqlConnectionString"].ConnectionString;
  19.  
  20.         MySqlConnection conn = new MySqlConnection(strConnectionString);
  21.         MySqlCommand command = conn.CreateCommand();
  22.         command.CommandText = "select * from lovemusicDebat WHERE id=?id;";
  23.         command.Parameters.Add("?id", MySqlDbType.Int16, 16).Value = User.Identity.Name;
  24.         conn.Open();
  25.         CategoryList.DataSource = command.ExecuteReader();
  26.         CategoryList.DataBind();
  27.         conn.Close();
  28.     }
  29.     private Northwind.ProductsDataTable allProducts = null;
  30.  
  31.     protected Northwind.ProductsDataTable GetProductsInCategory(int categoryID)
  32.     {
  33.         if (allProducts == null)
  34.         {
  35.             ProductsBLL productAPI = new ProductsBLL();
  36.             allProducts = productAPI.GetProducts();
  37.         }
  38.         allProducts.DefaultView.RowFilter = "id = " + categoryID;
  39.         return allProducts;
  40.     }
  41. }
Dec 14 '07 #1
2 2565
I hope this helps you get started at least. To work with an MySQL DataBase you need the MySQL ODBC Connector, available from the MySQL Website (Follow the link to the Download Area). Then you can connect to the MySQL Database using this example:

Expand|Select|Wrap|Line Numbers
  1. OdbcConnection Con = new OdbcConnection("DRIVER={MySQL ODBC 3.51 Driver};SERVER= YourServerIP;PORT=3306;DATABASE=YourDataBaseName;UID=YourDatabaseLogin;PWD=YourDatabasePassword;OPTION=3");
after including System.Data.Odbc

To get back to the original question:
If I understood you correctly, you want to create a Query that uses data from a previous query.

I hope a little example Code will show how to do that:

Expand|Select|Wrap|Line Numbers
  1. OdbcCommand Com = new OdbcCommand("PutYourFirstQueryHere"",Con); //Creates a new Command structure for the Con-Connection (you need to open it first, obviously)
  2. OdbcDataReader Reader; //Declares a Reader, to output the data read.
  3. OdbcDataReader Read2; //Declares a second Reader.
  4.  
  5. Reader = Com.ExecuteReader(); //Executes the Query and places the results into the 'Reader' Variable.
  6. //From this point forth, you can access the query results.
  7. while(Reader.Read()) //Loop is executed as long as there's data in the reader.
  8. {
  9. Com.CommandText = "SELECT * FROM Imagine WHERE iID = "+Reader["iID"]+";"; //This query text utilizes the data from the prior reader to create a new query.
  10. Read2 = Com.ExecuteReader();
  11. .
  12. .
  13. .
  14. }
I sure hope these code helps you a little and at least answered your question to a certain degree. If the answer doesn't match at all, you might want to explain a bit more what exactly you mean by 'Nested Repeater'.
Dec 14 '07 #2
Hi again...

With nested repeater i mean a repeater in a repeater. Like

[HTML]<repeater>
Repeater1 content with a other table, where there is a space called "UserID"
<repeater>
Repeater2 get content with other table where the user database is
</repeater>
More repeater1 content
</repeater>[/HTML]
Dec 14 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: mark | last post by:
My problem is I need to have a "nested" repeater. I have an array which I load into a hashtable - that part works great. I can setup the second repeater to work just fine, as long as it's not...
1
by: Bojesphob | last post by:
Can someone help? I have a nested repeater in which I wish to format one of the bits of data in currency. I know that the code for the regular repeater (which works fine in parent) is...
0
by: Ed Allan | last post by:
http://ejaconsulting.com/nestedrepeater/NestedRepeater.txt >-----Original Message----- >Doh! The HTML has all been rendered . . . > >Right click on this link and select 'Save target as ..' >to...
2
by: Stephen Miller | last post by:
I am using the OnItemDataBound event of Repeater control to nest a DataGrid within the Repeater. When I attempt to bind to the DataGrid using the DataSource method I get the error message "Object...
2
by: Colin Nicholls | last post by:
Platform: ASP.NET 1.1 I have a repeater nested inside another repeater. My outer repeater is looping fine. I am manually binding the inner repeater to a DataReader obtained from another...
2
by: mark | last post by:
(not sure if this is the correct group) My problem is I need to have a "nested" repeater. I have an array which I load into a hashtable - that part works great. I can setup the second repeater...
4
by: =?Utf-8?B?SmFtZXMgR2V1cnRz?= | last post by:
On my page, I have one repeater that contains a literal control and a nested repeater. The nested repeater contains a literal control. Both repeaters are databound with only one object (string). ...
1
by: andrew.douglas11 | last post by:
Hello all, Is it possible to share controls inside a child repeater? Here's the situation: I have a web page that needs to display data grouped by A, and alternatively by B (only one grouping...
2
by: ASF | last post by:
Hey all, I have a gridview which pulls from a BLL which pulls from a DAL (an .XSD file). Each row on that gridview has a nested repeater which pulls from another table. The code which populates...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.