Solved

URGENT - Master/Details Datagrid

Posted on 2006-10-20
5
192 Views
Last Modified: 2012-08-13
Experts,
    I've been fighting this for days now, and I still have not found the solution I'm looking for. What I would like to achieve is this: One datagrid with category information, and a child row that appears underneath the parent row displaying all the inventory items related to the parent row. Here's my db setup...

tblCategories:
ID (PK)
Prod_Type
Prod_Make
Prod_Model

tblInventory
ID (FK)
Prod_Location
Prod_Quantity

Does anyone know how I could setup an asp.net (vb) 1.1 datagrid to display this information how I want? It would be awesome if I could also edit the child rows and save back to the db... but if that can't happen I would be happy with just viewing the grid how I would like. Thanks in advance!!!

Jason
0
Comment
Question by:Yeavis
  • 2
  • 2
5 Comments
 
LVL 10

Expert Comment

by:jnhorst
ID: 17776968
Jason...

The first shot at this that I would take is to use a DataList for the categories.  In a data list you can put HTML into the item template to show for each category record.  What you could do is put an html table in the item template.  In the first table row, place controls to show the type, make, model and a regular html hyperlink (not the server control).  You will probably need some control that you set the display style to none that contains the category id.

Then in the second table row, do something like this:

<tr style="display:none">
     <td>...your data grid here </td>
</tr>

That regular html hyperlink in the first row, then, would call a JavaScript function to toggle the display style of the second row between an empty string (visible) and 'none'.

The data list has an OnItemDataBound event.  In this event you would get the category id from the hidden control in the top table row and query for the inventory and bind your datagrid to that data.

The main down side to this approach is that you cannot page a DataList, but otherwise this should work.

John

0
 

Author Comment

by:Yeavis
ID: 17777053
John,
   Thanks for the response. I see where you're coming from in your approach to the answer for this problem, however I have seen it done using a datagrid. My memory escapes me but I viewed a tutorial on this no later than a month ago.. and now I can't find that page again!! Go figure.. anyway, I want to go this route because it would be cleaner for the end user and it wouldn't require me to have two grids. If you have any further input, please feel free...

Jason
0
 
LVL 10

Accepted Solution

by:
jnhorst earned 500 total points
ID: 17777824
0
 
LVL 12

Expert Comment

by:deanvanrooyen
ID: 17778787
hi,

you could keep the datagrid, add a <br/><div in the column tag with the some label controls and mark the div as display:none as john suggested and add add a toggle js function in the itembound event eg I had a image to toggle a calendar control in the grid

    protected void GridView3_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            try
            {
                Image im = (Image)e.Row.Controls[0].Controls[1];
                Label lb = (Label)e.Row.Controls[0].Controls[3];

                if (lb.Text.Length > 0)
                    Image1.Visible = true;

                lb.Style["Display"] = "none";
                im.Attributes.Add("onmouseover", "ToggleCal('" + lb.ClientID.ToString() + "');");
                im.Attributes.Add("onmouseout", "ToggleCal('" + lb.ClientID.ToString() + "');");
            }
            catch (Exception me)
            {
            }
        }
    }

toggle java that i used from sammy


<head runat="server">
    <title>Untitled Page</title>
    <link type="text/css" href="StyleSheet.css" media="all" rel="Stylesheet" />
    <script type="text/javascript">

function getObj(name)
{
  if (document.getElementById)
  {
        this.obj = document.getElementById(name);
      this.style = document.getElementById(name).style;
  }
  else if (document.all)
  {
      this.obj = document.all[name];
      this.style = document.all[name].style;
  }
  else if (document.layers)
  {
         this.obj = document.layers[name];
         this.style = document.layers[name];
  }
}

function ToggleCal(c){//Toggle control by row event

if(document.getElementById('' + c + '').style.display=='none')
{
document.getElementById('' + c + '').style.display='block';
}
else
document.getElementById('' + c + '').style.display='none';
}
function ToggleOff(c){//Toggle control off
document.getElementById('' + c + '').style.display='none';
}
function ToggleOn(c){//Toggle control on
document.getElementById('' + c + '').style.display='block';
}
</script>

</head>
0
 

Author Comment

by:Yeavis
ID: 17781368
Awesome... thanks for all the help guys!
0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Name space syntax error 12 60
Not showing JavaScript in the list 5 55
ASP.net Have sliders change in order 2 24
insert value of checklistbox checked 4 27
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question