Click here to Skip to main content
15,896,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi, i am developing one site for tools which has several brand.

so i want to categories the brand in

first div should contain : 0-9, A-B, C-D , E-F .....y-z.

in below should show.

0-9

here, 0-9 brands,

A-B

here, A-B's brands,

.

.

.

Y-Z

here, y-Z' s brands.

how to do above functionalities using asp.net c#? help needed.
Posted
Comments
CodeBlack 7-Nov-13 6:09am    
can you please explain your question in more details ?
christhuxavier 7-Nov-13 6:20am    
hi i have brand for tools for example consider bosch is a brand. so, this bosch contains many categories so, bosch is 'B' serial in alphabetical right? like that there are several brand which some start with A or B or C or D .......or Z serial. so, now i want to seperate A-B brand, C-D brand......Y-Z brand so that user choose which they need. how to do in asp.net c#. i think we have to use datalist concept. please guide me in correct way.
CodeBlack 7-Nov-13 6:32am    
so you mean, A-B means all the brands which are starting from A or B, C-D means all the brand starting from C or D right ?
christhuxavier 7-Nov-13 6:53am    
Yes you are correct. that is what i need.

1 solution

You can bind it as shown below :

ASPX Page :
XML
<asp:DataList runat="server" ID="listBrands" OnItemDataBound="listBrands_OnItemDataBound">
               <ItemTemplate>
                   <div style="border: 1px solid #777"></div>
                   <div>Categories : <%# Container.DataItem %> </div>
                   <div>
                       <asp:GridView runat="server" ID="gridBrands"></asp:GridView>
                   </div>
               </ItemTemplate>
           </asp:DataList>


ASPX.cs page :
C#
protected void Page_Load(object sender, EventArgs e)
{
    this.BindList();
}

private void BindList()
{
    var categories = new List<string>();
    for (var i = 65; i < 91; i = i + 2)
    {
        var category = string.Empty;
        categories.Add(((char)i) + "-" + ((char)(i + 1)));
    }

    categories.Insert(0, "0-9");
    this.listBrands.DataSource = categories;
    this.listBrands.DataBind();
}

protected void listBrands_OnItemDataBound(object sender, DataListItemEventArgs e)
{
    var category = e.Item.DataItem;

    var categoryList = e.Item.DataItem.ToString().Split('-');
    var brands = e.Item.FindControl("gridBrands") as GridView;
    if (brands != null)
    {
        // Bind the grid 'brands' based on categoryList object
    }
}
 
Share this answer
 
v2
Comments
christhuxavier 7-Nov-13 11:31am    
Thank you
CodeBlack 7-Nov-13 11:46am    
Hope you like the solution. Dont forget to mark this solution as an answer and rate this solution. so that it may help to other users as well. Happy coding :-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900