Solved

URGENT - Master/Details Datagrid

Posted on 2006-10-20
5
190 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
Comment Utility
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
Comment Utility
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
Comment Utility
0
 
LVL 12

Expert Comment

by:deanvanrooyen
Comment Utility
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
Comment Utility
Awesome... thanks for all the help guys!
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now