Get Category ID's

Last post 03-14-2011, 10:48 PM by Kenneth. 4 replies.
Sort Posts: Previous Next
  •  02-16-2011, 7:26 PM 66268

    Get Category ID's

    Is there a way to get the category ID's and next category ID programatically?
  •  02-17-2011, 7:46 AM 66278 in reply to 66268

    Re: Get Category ID's

    OK, I got this piece of code tfrom a previous post that gets the data I'm looking for. Now what I want ot do is bind it to a dropdownlist if possible. Have the categoryID as the datavaluefield and the title as the datatextfield.
     

    using (DotNetGallery.GalleryDataProvider provider = DotNetGallery.GalleryDataProvider.CreateInstance(Context, "~/MyGallery/"))

    {

    //get all category

    string[] categoryArray = provider.GetCategoryArray();

    for (int i = 0; i < categoryArray.Length; i++)

    {

    string title;

    string description;

    string properties;

    string physicalPath = provider.PhysicalDirectory;

    string virtualPath = provider.VirtualDirectory;

     

    if (provider.GetCategoryInfo(categoryArray[i].ToString(), out title, out description, out properties))

    {

    //show all title in label1

    //title is the name of the category

     

    string s2 = "Category id = " + (i+1).ToString() + " title = " + title + "<br/>";

    Label1.Text += s2;

    }

    }

    }

  •  02-21-2011, 12:27 AM 66319 in reply to 66278

    Re: Get Category ID's

    Hi englishsteve,
     
    Please try the example below
     
    1. <%@ Page Language="c#" AutoEventWireup="false" %>  
    2.   
    3. <%@ Register TagPrefix="DotNetGallery" Namespace="DotNetGallery" Assembly="DotNetGallery" %>  
    4.   
    5. <script runat="server">  
    6.       
    7.     protected override void OnInit(EventArgs e)  
    8.     {  
    9.         base.OnInit(e);  
    10.   
    11.         GalleryBrowser1.Layout = "SlideShow";  
    12.         GalleryBrowser1.AllowEdit = true;  
    13.         GalleryBrowser1.AllowPostComment = true;  
    14.         GalleryBrowser1.AllowShowComment = true;  
    15.         using (DotNetGallery.GalleryDataProvider provider = DotNetGallery.GalleryDataProvider.CreateInstance(Context, "~/GalleryFiles/"))  
    16.         {  
    17.             string[] categoryArray = provider.GetCategoryArray();  
    18.             for (int i = 0; i < categoryArray.Length; i++)  
    19.             {  
    20.                 string title;  
    21.                 string description;  
    22.                 string properties;  
    23.                 string physicalPath = provider.PhysicalDirectory;  
    24.                 string virtualPath = provider.VirtualDirectory;  
    25.                 ListItem l1 = new ListItem();  
    26.                 ddlCategoryID.Items.Add(l1);  
    27.                 if (provider.GetCategoryInfo(categoryArray[i].ToString(), out title, out description, out properties))  
    28.                 {  
    29.                     l1.Text = categoryArray[i][0].ToString();  
    30.                     l1.Value = title;  
    31.                 }  
    32.   
    33.             }  
    34.   
    35.         }  
    36.     }  
    37. </script>  
    38.   
    39. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">  
    40. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">  
    41. <head>  
    42.     <title>SlideShow Layout - DotNetGallery</title>  
    43.     <link href="Sample.css" type="text/css" rel="stylesheet" />  
    44. </head>  
    45. <body>  
    46.     <form id="form1" runat="server">  
    47.         <a href="#" onclick="thegallerybrowser.ShowEditor();return false;">Admin Console</a>  
    48.         <asp:DropDownList ID="ddlCategoryID" runat="server">  
    49.         </asp:DropDownList>  
    50.         <DotNetGallery:GalleryBrowser runat="server" ID="GalleryBrowser1" Width="720" Height="400" />  
    51.     </form>  
    52. </body>  
    53. </html> 
     Regards,
     
    ken
  •  03-14-2011, 7:37 AM 66641 in reply to 66319

    Re: Get Category ID's

    Thanks Ken. I only just circled back and saw your reply. It appeared to work and then I noticed once I reached album category 10, it shows as 1 in the dropdown list. I'm not sure how to fix that.
  •  03-14-2011, 10:48 PM 66661 in reply to 66641

    Re: Get Category ID's

    Hi englishsteve,
     
    Please try the new example
     
    1. <%@ Page Language="c#" AutoEventWireup="false" %>  
    2.   
    3. <%@ Register TagPrefix="DotNetGallery" Namespace="DotNetGallery" Assembly="DotNetGallery" %>  
    4.   
    5. <script runat="server">    
    6.          
    7.     protected override void OnInit(EventArgs e)  
    8.     {  
    9.         base.OnInit(e);  
    10.   
    11.         GalleryBrowser1.Layout = "SlideShow";  
    12.         GalleryBrowser1.AllowEdit = true;  
    13.         GalleryBrowser1.AllowPostComment = true;  
    14.         GalleryBrowser1.AllowShowComment = true;  
    15.         using (DotNetGallery.GalleryDataProvider provider = DotNetGallery.GalleryDataProvider.CreateInstance(Context, "~/GalleryFiles/"))  
    16.         {  
    17.             string[] categoryArray = provider.GetCategoryArray();  
    18.   
    19.             for (int i = 0; i < categoryArray.Length; i++)  
    20.             {  
    21.                 string title;  
    22.                 string description;  
    23.                 string properties;  
    24.                 string physicalPath = provider.PhysicalDirectory;  
    25.                 string virtualPath = provider.VirtualDirectory;  
    26.                 ListItem l1 = new ListItem();  
    27.                 ddlCategoryID.Items.Add(l1);  
    28.                 if (provider.GetCategoryInfo(categoryArray[i], out title, out description, out properties))  
    29.                 {  
    30.                     l1.Text = categoryArray[i];  
    31.                     l1.Value = title;  
    32.                 }  
    33.   
    34.             }  
    35.   
    36.         }  
    37.     }    
    38. </script>  
    39.   
    40. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">  
    41. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">  
    42. <head>  
    43.     <title>SlideShow Layout - DotNetGallery</title>  
    44.     <link href="Sample.css" type="text/css" rel="stylesheet" />  
    45. </head>  
    46. <body>  
    47.     <form id="form1" runat="server">  
    48.         <a href="" onclick="thegallerybrowser.ShowEditor();return false;">Admin Console</a>  
    49.         <asp:DropDownList ID="ddlCategoryID" runat="server">  
    50.         </asp:DropDownList>  
    51.         <DotNetGallery:GalleryBrowser runat="server" ID="GalleryBrowser1" Width="720" Height="400" />  
    52.     </form>  
    53. </body>  
    54. </html> 
     
    Regards,
     
    ken
View as RSS news feed in XML