|
I am just learning ASP.NET and I am trying to create a Master / Detail set-up where I have a list of categories displayed in a DataGrid in my user control and when someone clicks one of the category links they are taken to the products page where all the relevant products are displayed in a DataList. My products page Datalist will retrieve 4 columns from my database products table including an image and also will need to include a link to the Master Products page. Can anyone help me with this, Im using C# and have succesfully created the category links datagrid to go to the Products page but Im having trouble displaying the relevant products in the DataList.
Cheers
|
|
|
What is your specific problem or error? Is it a .NET Event problem, or a Web Form/Control problem, or is it a database problem?
|
|
|
|
|
.NET Event problem. I have managed to link the category links to my product detail page which then displays all my products using a DataList but I need to only display the relevant products for the selected category, this is where Im stuck.
Ive linked the categories to the products using:
productDetail.aspx?id={0} in the DataGrid. Now I need to add some C# that displays only the relevant products for the selected category by linking the DataGrid (in the user control) to my DataList on my products page.
|
|
|
hi,
if u have assigned a DataKeyField to ur datagrid u will get the value assigned to it by id={0}, now u can access this value with Request.Querystirng["id"] and with that id u cag get the assosiated product for that category.
Manoj
|
|
|
thanks for reply, still a bit stuck. Here's my C# for products detail page:
private void Page_Load(object sender, System.EventArgs e)
{
int catID = 0;
if (Request.QueryString["CategoryID"] == null)
{
Response.Redirect( "/forum/default.html" );
}
else
{
catID = Convert.ToInt32Request.QueryString "CategoryID"]);
}
Label1.Text = catID.ToString();
sqlDataAdapter1.Fill( dataSet1 );
DataList1.DataSource = dataSet1;
DataList1.DataBind();
sqlConnection1.Close();
}
Put Label in to test and it displays CategoryID, obvoiusly missing a bit of code that places the relevant products in my DataList. Any help would be great, cheers.
|
|
|
I'm still confused.
There are two data models you can use with ASP.NET. One is to pull everything you need from the database, and store it in ADO.NET DataSets. DataSets are complex objects, in fact, they are miniature in-memory databases, with multiple tables and relationships.
That appears to be what you're trying to do, pull a Master table and a Detail table across into separate DataTables, build a relationship in the DataSet, etc.
Don't do that. It's way too memory intensive.
Instead, you can use DataReaders. A DataReader is a single read-only, forward-only recordset that does NOT persist. The idea is, go in, get what you want, process the results, and get out.
So for your scenario I would suggest that you create a query, or better yet, a stored procedure, for each process. One to get the Master records, and a second to get the Detail records.
When a user clicks a Master row, get the data from that row, and pass it as a parameter to your second query.
Are you with me so far? Let's stop here and see if you have any questions.
|
|
|
|
|
|
|
|
|
|