Question

<TBODY> in Table Control

Asked by: arbert

Ok, I know that .NET 2.0 is going to give us the ability to assign a "TableSection" property to a row on the table control.

But until then, can someone give me some pointers or ideas on how to get around the limitation of not being able to include <TBODY> tags in the table control.

Basically, we're creating a hierarchy on the fly and we need to hide/display multiple rows at a time within the same table.  I have it working beautifully in old ASP with CSS and the VISIBLE property of the ID on the TBODY.

So, we have a list of categories--these should always be visible.  Under those is a list of subcategorys--these are only visible when the category is clicked.  Under the subcategory is an actual list of selectible options and these are only visible when the subcategory is clicked.



I know we could make the table control postback and make the rows visible/hidden, but I think it's kind of pointless to make another trip to the server.

Thanks
Brett

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2005-06-18 at 18:10:18ID21463018
Tags

tbody

,

table

,

control

Topic

Programming for ASP.NET

Participating Experts
2
Points
500
Comments
9

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. What good is TBODY?
    Hello. I have been hardcoding HTML tables for years, and have never used TBODY. I have seen TBODY used in many tables: <TABLE cellSpacing=0 cellPadding=0 width="100%" border=0> <TBODY> <TR> <TD> C...
  2. <TBODY> tag ??
    I have this "<TBODY>" tag in some of my Tables. I copied a lot of HTML and I guess it came in from that. Should I delete them from my Tables? When I make new Tables I don't use that tag. Can I leave them or should I remove them? <TABLE border=0> &l...
  3. Add THEAD or TBODY element to the TABLE() object.
    Hi. I'm trying to create a server control that builds a Table() object for me. However I need to some how add a <THEAD> and/or <TBODY> element to my control. But I can't seem to figure out how to do this. can someone please post some code that creates a Table...
  4. table : TBODY STYLE tags
    Hello, could someone please take a look at this piece of codes - In the "tbody" tag, there's a piece of CSS " style="max-height:12ex;overflow:auto;" this CSS codes is to make the TBODY section scrollable so that the header and footer remain visible as...
  5. HMTL - Looping <TBody>
    I need help with my <TBODY> tags graping the right rows when i hidden them. For some reason when i hide my DIR<TBODY> it only grabs the first MANAGER. I think it might be a problem with my loop but i cant find it. DIR ---MANAGER ---------EMEPLOYEE ---------EMEPLOY...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: HeadspacePosted on 2005-06-18 at 20:53:59ID: 14250569

Rather than using the asp:table control, can you use an html table instead? You can build it in the codebehind using the HtmlGenericControl and LiteralControl classes.  once you've built the table, you can either place it inside of another control (e.g. a predefined Panel control) or simply add it directly to the page.

 

by: amit_gPosted on 2005-06-18 at 23:45:08ID: 14250827

Something like this...

****************************** WebForm5.aspx ******************************

<%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm5.aspx.vb" Inherits="WebApplication1.WebForm5"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
  <head>
    <title>WebForm5</title>
    <meta name="GENERATOR" content="Microsoft Visual Studio.NET 7.0">
    <meta name="CODE_LANGUAGE" content="Visual Basic 7.0">
    <meta name=vs_defaultClientScript content="JavaScript">
    <meta name=vs_targetSchema content="http://schemas.microsoft.com/intellisense/ie5">
    <style>
    .Category {
        background-color: #CECECE;
    }
    .SubCategoryHidden {
        visibilitiy: hidden;
        display: none;
    }
    .SubCategoryVisible {
        visibilitiy: visible;
        display: block;
    }
    </style>
    <script language="javascript">
    function ShowSubCategories(oThis)
    {
        var CurrentCategoryIndex = oThis.rowIndex;
        var Rows = oThis.parentNode.rows;

        for (i = 1 ; i < Rows.length ; i++)
        {
            Rows[i].className = Rows[i].className.replace("SubCategoryVisible", "SubCategoryHidden");
        }

        for (i = oThis.rowIndex + 1 ; i < Rows.length ; i++)
        {
            if (Rows[i].className == "Category")
            {
                break;
            }
            else
            {
                Rows[i].className = "SubCategoryVisible";
            }
        }
    }
    </script>
  </head>
  <body OnLoad="ShowSubCategories(document.getElementById('MyDataGrid').rows[1])">

    <form id="MyForm" method="post" runat="server">
        <asp:DataGrid ID="MyDataGrid" Runat="server" CellPadding="0" CellSpacing="0" BorderWidth="1"></asp:DataGrid>
    </form>

  </body>
</html>

****************************** WebForm5.aspx.vb ******************************

Public Class WebForm5
    Inherits System.Web.UI.Page
    Protected WithEvents MyDataGrid As System.Web.UI.WebControls.DataGrid

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If (Not IsPostBack()) Then
            Call BindData()
        End If
    End Sub

    Sub BindData()
        Dim MyDataTable As New DataTable()

        MyDataTable.Columns.Add("CategoryID", Type.GetType("System.Int32"))
        MyDataTable.Columns.Add("CategoryName", Type.GetType("System.String"))
        MyDataTable.Columns.Add("SubCategoryID", Type.GetType("System.Int32"))
        MyDataTable.Columns.Add("SubCategoryName", Type.GetType("System.String"))

        Dim MyDataRow As DataRow
        Dim i, j As Int32

        For i = 1 To 5
            MyDataRow = MyDataTable.NewRow()
            MyDataRow.Item("CategoryID") = 100 + i
            MyDataRow.Item("CategoryName") = "CategoryName" & (100 + i)
            MyDataRow.Item("SubCategoryID") = 0
            MyDataRow.Item("SubCategoryName") = ""
            Call MyDataTable.Rows.Add(MyDataRow)

            For j = 1 To 3
                MyDataRow = MyDataTable.NewRow()
                MyDataRow.Item("CategoryID") = 100 + i
                MyDataRow.Item("CategoryName") = "CategoryName" & (100 + i)
                MyDataRow.Item("SubCategoryID") = 1000 + j
                MyDataRow.Item("SubCategoryName") = "SubCategoryName" & (1000 + j)
                Call MyDataTable.Rows.Add(MyDataRow)
            Next
        Next

        MyDataGrid.DataSource = MyDataTable
        Call MyDataGrid.DataBind()
    End Sub

    Private Sub MyDataGrid_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles MyDataGrid.ItemDataBound
        If ((e.Item.ItemType = ListItemType.Item) Or (e.Item.ItemType = ListItemType.AlternatingItem)) Then
            If (e.Item.DataItem("SubCategoryID") <> 0) Then
                e.Item.CssClass = "SubCategoryHidden"
            Else
                e.Item.CssClass = "Category"
                e.Item.Attributes.Add("onclick", "ShowSubCategories(this)")
            End If
        End If
    End Sub
End Class

 

by: arbertPosted on 2005-06-19 at 09:33:42ID: 14252338

amit, that's pretty cool (I'll add it to my tricks and give you some points), but I really need the table control so I can make it look more hierarchial.

Alas, I think maybe Headspace  is correct and I'll have to use a literal.

 

by: amit_gPosted on 2005-06-19 at 10:49:08ID: 14252567

Could you please post a sample HTML that you are aiming for.

 

by: arbertPosted on 2005-06-19 at 11:44:42ID: 14252803

Sure, it's a bit messy, but basically the "Kitchen" section has the functionality that I'm going for:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
      <head>
            <title>hide or display trs</title>
            <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8">
            <style type="text/css">

a:link    {
  /* Applies to all unvisited links */
  text-decoration:  none;
  font-weight:      bold;
 
  color:            black;
  }
a:visited {
  /* Applies to all visited links */
  text-decoration:  none;
  font-weight:      bold;
 
  color:            darkblue;
  }
a:hover   {
  /* Applies to links under the pointer */
  text-decoration:  underline;
  font-weight:      bold;
  background-color: blue;
  color:            #fff;
  }
a:active  {
  /* Applies to activated links */
  text-decoration:  none;
  font-weight:      bold;
  background-color: black;
  color: white;
  }


#container {
     width:260px;
     margin:20px auto;
 }
#tbl {
     font-family:verdana,arial,helvetica,sans-serif;
     font-size:20px;
     
     border:inset 6px #666;
 }
#tbl td {
     width:82px;
     height:50px;
     border:solid 1px #000;
     text-align:center;
     line-height:50px;
 }

/*//]]>*/
            </style>
            <script type="text/javascript">
//<![CDATA[
function getdisplay(id){
 if (document.getElementById(id).style.display=='block') {
    document.getElementById(id).style.display='none'  
    document.getElementById('bath2').checked=false    ;
    document.getElementById('kitchen2').checked=false    ;
   }
}

function hideShow(id) {

if(document.getElementById(id).style.display=="none") {
   document.getElementById(id).style.display="block";

 }
else {
   document.getElementById(id).style.display="none";
 
  }
 

 }


//]]>
            </script>
      </head>
      <body onload="hideShow('tr0');hideShow('tr11');hideShow('bathroom');hideShow('kitchen')">
      <form name="order">
            <table id="tbl3" cellSpacing="0" cellPadding="0" width="80%" border="0">
                  <tr bgColor="lightskyblue">
                        <a onclick="getdisplay('bathroom');getdisplay('kitchen');hideShow('tr0');hideShow('tr11');return false;" href="">Windows</a>
                  </tr>
                  <tr id="tr0">
                        <td>&nbsp;&nbsp;&nbsp; <INPUT onclick="hideShow('bathroom')" type="checkbox" id="bath2"><b> Bath</b></td>
                  </tr>
                  <tbody id="bathroom">
                        <tr>
                               <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input type="radio" name="rad1">30"
                                    x 48" Vertical Safety: Over Oasis Tub 100 Series
                              </td>
                        <tr>
                              <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input type="radio" name="rad1" ID="Radio1" VALUE="Radio1">46"
                                    x 53" Vertical Safety: Over Oasis Tub</td>
                        <tr>
                              <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input type="radio" name="rad1" ID="Radio2" VALUE="Radio2">30"
                                    x 40" Vertical</td>
                        <tr>
                              <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input type="radio" name="rad1" ID="Radio3" VALUE="Radio2">14"
                                    x 40" Veritcal</td>
                        </tr>
                  </tbody>
                  <tr id="tr11">
                        <td>&nbsp;&nbsp;&nbsp; <input onclick="hideShow('kitchen')" type="checkbox" name="Checkbox1" id="kitchen2">&nbsp;<b>Kitchen</b></td>
                  </tr>
                  <tbody id="kitchen">
                        <tr>
                              <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input type="radio" name="Radio3">30"
                                    x 40" Vertical</td>
                        <tr>
                              <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input type="radio" CHECKED value="Radio4" name="Radio3">46"
                                    x 40" Vertical</td>
                        <tr>
                              <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input type="radio" CHECKED value="Radio4" name="Radio3" ID="Radio4">62"
                                    x 40" Picture with Two Side Verticals</td>
                        </tr>
                  </tbody>
            </table>
            <table id="Table1" cellSpacing="0" cellPadding="0" width="80%" border="0">
                  <tr bgColor="lightskyblue">
                        <a onclick="hideShow('tr0');hideShow('tr11');return false;" href="">Doors</a>
                  </tr>
            </table>
            <input type=hidden name="page">
            </form>
      </body>
</html>

 

by: HeadspacePosted on 2005-06-19 at 20:42:02ID: 14254219

oooh, that Will be messy!  Here's the general idea.  I threw the table into a predefined panel, but you can do whatever you like.  all of your css code can go in the page as is, or in a stylesheet of course.  this also holds for the javascript, unless you'd rather bring it in from the codebehind with RegisterStartupScript or RegisterClientScriptBlock.  if you need it in vb.net rather than c#, let me know:

private void Page_Load(object sender, System.EventArgs e) <--- or whatever method you need it in : )
{
      HtmlGenericControl tbl = new HtmlGenericControl("Table");
      tbl.Attributes.Add ("id", "tbl3");
      tbl.Attributes.Add("cellSpacing", "0");
      tbl.Attributes.Add("cellPadding", "0");
      tbl.Attributes.Add("width", "80%");
      tbl.Attributes.Add("border", "0");
      HtmlGenericControl tbody = new HtmlGenericControl("TBODY");
      HtmlGenericControl tr = new HtmlGenericControl("tr");
      tr.Attributes.Add("bgColor", "lightskyblue");
      HtmlGenericControl a = new HtmlGenericControl("a");
                a.Attributes.Add("onclick", "getdisplay('bathroom');getdisplay('kitchen');hideShow('tr0');" +
                                         "hideShow('tr11');return false;\"href=\"\">Windows");
      tr.Controls.Add(a);
      tbody.Controls.Add(tr);
      HtmlGenericControl td = new HtmlGenericControl("td");
      LiteralControl lt = new LiteralControl("Literal Control!");
      td.Controls.Add(lt);
      tr = new HtmlGenericControl("tr");
      tr.Controls.Add(td);
      tbody.Controls.Add(tr);
      tbl.Controls.Add(tbody);
      panel1.Controls.Add(tbl);
}

 

by: arbertPosted on 2005-06-19 at 21:07:42ID: 14254267

"oooh, that Will be messy! "

Thanks for that--glad I'm not the only one that thought that :)    I will say, .NET does make a lot of things really easy.  Conversely, there are definately some things that are easier (granted messier to maintain) to do in good old ASP.

I'll take a look at your snippet tomorrow headspace--looks good though.

 

by: amit_gPosted on 2005-06-20 at 01:29:04ID: 14254995

>>Conversely, there are definately some things that are easier (granted messier to maintain) to do in good old ASP.

True but we could still use asp.net as simple asp :) Generally there is a way to do things that could have been done in ASP. Sometimes the way is difficult to find as we still have long way to come out of asp shell.

Here is the modified version. I am not saying that you must use DataGrid but just wanted to demonstrate that DataGrid can also do the same thing although in a "messy way". Which way is less messy is for you to decide :)

<%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm5.aspx.vb" Inherits="WebApplication1.WebForm5"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
  <head>
    <title>WebForm5</title>
    <meta name="GENERATOR" content="Microsoft Visual Studio.NET 7.0">
    <meta name="CODE_LANGUAGE" content="Visual Basic 7.0">
    <meta name=vs_defaultClientScript content="JavaScript">
    <meta name=vs_targetSchema content="http://schemas.microsoft.com/intellisense/ie5">
    <style>
    .Category {
            background-color: #CECECE;
    }
    .SubCategoryHidden {
            visibilitiy: hidden;
            display: none;
            background-color: #FFEEEE;
    }
    .SubCategoryVisible {
            visibilitiy: visible;
            display: block;
            background-color: #FFEEEE;
    }
    .Sub2CategoryHidden {
            visibilitiy: hidden;
            display: none;
            background-color: #EEFFFF;
    }
    .Sub2CategoryVisible {
            visibilitiy: visible;
            display: block;
            background-color: #EEFFFF;
    }
    </style>
    <script language="javascript">
    function ShowSubCategories(oThis)
    {
            var CurrentCategoryIndex = oThis.rowIndex;
            var Rows = oThis.parentNode.rows;

            for (i = 1 ; i < Rows.length ; i++)
            {
                  Rows[i].className = Rows[i].className.replace("SubCategoryVisible", "SubCategoryHidden");
                  Rows[i].className = Rows[i].className.replace("Sub2CategoryVisible", "Sub2CategoryHidden");
            }

            for (i = CurrentCategoryIndex + 1 ; i < Rows.length ; i++)
            {
                  if (Rows[i].className == "Category")
                  {
                        break;
                  }
                  else
                  {
                        Rows[i].className = Rows[i].className.replace("SubCategoryHidden", "SubCategoryVisible");

                        if ((Rows[i].getElementsByTagName("INPUT").length == 1) && (Rows[i].getElementsByTagName("INPUT")[0].type == "checkbox") && (Rows[i].getElementsByTagName("INPUT")[0].checked))
                        {
                              for (j = i + 1 ; j < Rows.length ; j++)
                              {
                                    if (Rows[j].className.indexOf("Sub2Category") == -1)
                                    {
                                          break;
                                    }
                                    else
                                    {
                                          Rows[j].className = "Sub2CategoryVisible";
                                    }
                              }
                        }
                  }
            }
    }

    function ShowSubSubCategories(oThis)
    {
            var CurrentSubCategoryIndex = oThis.parentNode.parentNode.rowIndex;
            var Rows = oThis.parentNode.parentNode.parentNode.rows;

            /*
            for (i = 1 ; i < Rows.length ; i++)
            {
                  Rows[i].className = Rows[i].className.replace("Sub2CategoryVisible", "Sub2CategoryHidden");
            }
            */

            for (i = CurrentSubCategoryIndex + 1 ; i < Rows.length ; i++)
            {
                  if (Rows[i].className.indexOf("Sub2Category") == -1)
                  {
                        break;
                  }
                  else
                  {
                        Rows[i].className = oThis.checked ? "Sub2CategoryVisible" : "Sub2CategoryHidden";
                  }
            }
    }
    </script>
  </head>
  <body OnLoad="ShowSubCategories(document.getElementById('MyDataGrid').rows[1])">

    <form id="MyForm" method="post" runat="server">
            <asp:DataGrid ID="MyDataGrid" Runat="server" CellPadding="0" CellSpacing="0" BorderWidth="1" AutoGenerateColumns="False">
                  <Columns>
                        <asp:TemplateColumn>
                              <ItemTemplate>
                                    <asp:Label ID="lblCategory" Runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "CategoryName") %>'></asp:Label>
                                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                    <asp:CheckBox ID="chkSubCategory" Runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "SubCategoryName") %>'></asp:CheckBox>
                                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                    <asp:RadioButton ID="rbtnSubSubCategory" Runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "SubSubCategoryName") %>'></asp:RadioButton>
                              </ItemTemplate>
                        </asp:TemplateColumn>
                        <asp:BoundColumn DataField="CategoryID" Visible="False"></asp:BoundColumn>
                        <asp:BoundColumn DataField="SubCategoryID" Visible="False"></asp:BoundColumn>
                        <asp:BoundColumn DataField="SubSubCategoryID" Visible="False"></asp:BoundColumn>
                  </Columns>
            </asp:DataGrid>
    </form>

  </body>
</html>

Public Class WebForm5
    Inherits System.Web.UI.Page
    Protected WithEvents MyDataGrid As System.Web.UI.WebControls.DataGrid

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If (Not IsPostBack()) Then
            Call BindData()
        End If
    End Sub

    Sub BindData()
        Dim MyDataTable As New DataTable()

        MyDataTable.Columns.Add("CategoryID", Type.GetType("System.Int32"))
        MyDataTable.Columns.Add("CategoryName", Type.GetType("System.String"))
        MyDataTable.Columns.Add("SubCategoryID", Type.GetType("System.Int32"))
        MyDataTable.Columns.Add("SubCategoryName", Type.GetType("System.String"))
        MyDataTable.Columns.Add("SubSubCategoryID", Type.GetType("System.Int32"))
        MyDataTable.Columns.Add("SubSubCategoryName", Type.GetType("System.String"))

        Dim MyDataRow As DataRow
        Dim i, j, k As Int32

        For i = 1 To 5
            MyDataRow = MyDataTable.NewRow()
            MyDataRow.Item("CategoryID") = 10 + i
            MyDataRow.Item("CategoryName") = "CategoryName" & (10 + i)
            MyDataRow.Item("SubCategoryID") = 0
            MyDataRow.Item("SubCategoryName") = ""
            MyDataRow.Item("SubSubCategoryID") = 0
            MyDataRow.Item("SubSubCategoryName") = ""
            Call MyDataTable.Rows.Add(MyDataRow)

            For j = 1 To 3
                MyDataRow = MyDataTable.NewRow()
                MyDataRow.Item("CategoryID") = 10 + i
                MyDataRow.Item("CategoryName") = "CategoryName" & (10 + i)
                MyDataRow.Item("SubCategoryID") = 100 + j
                MyDataRow.Item("SubCategoryName") = "SubCategoryName" & (100 + j)
                MyDataRow.Item("SubSubCategoryID") = 0
                MyDataRow.Item("SubSubCategoryName") = ""
                Call MyDataTable.Rows.Add(MyDataRow)

                For k = 1 To 2
                    MyDataRow = MyDataTable.NewRow()
                    MyDataRow.Item("CategoryID") = 10 + i
                    MyDataRow.Item("CategoryName") = "CategoryName" & (10 + i)
                    MyDataRow.Item("SubCategoryID") = 100 + j
                    MyDataRow.Item("SubCategoryName") = "SubCategoryName" & (100 + j)
                    MyDataRow.Item("SubSubCategoryID") = 1000 + k
                    MyDataRow.Item("SubSubCategoryName") = "SubSubCategoryName" & (1000 + j)
                    Call MyDataTable.Rows.Add(MyDataRow)
                Next
            Next
        Next

        MyDataGrid.DataSource = MyDataTable
        Call MyDataGrid.DataBind()
    End Sub

    Private Sub MyDataGrid_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles MyDataGrid.ItemDataBound
        If ((e.Item.ItemType = ListItemType.Item) Or (e.Item.ItemType = ListItemType.AlternatingItem)) Then
            If (e.Item.DataItem("SubSubCategoryID") <> 0) Then
                e.Item.CssClass = "Sub2CategoryHidden"

                e.Item.FindControl("lblCategory").Visible = False
                e.Item.FindControl("chkSubCategory").Visible = False
            Else
                If (e.Item.DataItem("SubCategoryID") <> 0) Then
                    e.Item.CssClass = "SubCategoryHidden"

                    e.Item.FindControl("lblCategory").Visible = False
                    e.Item.FindControl("rbtnSubSubCategory").Visible = False

                    CType(e.Item.FindControl("chkSubCategory"), CheckBox).Attributes.Add("onclick", "ShowSubSubCategories(this)")
                Else
                    e.Item.CssClass = "Category"

                    e.Item.FindControl("chkSubCategory").Visible = False
                    e.Item.FindControl("rbtnSubSubCategory").Visible = False

                    e.Item.Attributes.Add("onclick", "ShowSubCategories(this)")
                End If
            End If
        End If
    End Sub
End Class

 

by: arbertPosted on 2005-06-20 at 19:20:35ID: 14262469

OMG amit, that's awesome.  I toyed around with a template and finally figured it was too rigid to do what I needed--boy was I wrong.  This is TOTALLY going to make my job much easier.

I wish we could give more than 500 on a question so I could give you each 500.

I hope nobody is offended by the split.

brett

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...