Solved

Hide a separator in a datalist ASP.Net

Posted on 2010-09-22
11
844 Views
Last Modified: 2012-06-27
With reference to: http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_24005751.html

Hi, can you please help more with Step 3? "After retrieving your data store off the record count and calculate IndexToClear like this"

Where do I put this in the code?

Thanks
Paul
0
Comment
Question by:auxploeb
  • 6
  • 2
11 Comments
 
LVL 41

Accepted Solution

by:
guru_sami earned 500 total points
ID: 33739188
how are you populating your DataList? Using SqlDataSource or in code-behind.
Step 3 is getting data in CodeBehind. If you are doing so then it should be right after you retrieve your data.

If SDS, you can try doing in OnSelected event handler.
0
 

Author Comment

by:auxploeb
ID: 33739289
I'm using a SqlDataSource. It's still not working. Any ideas?
<asp:SqlDataSource ID="sqlGenreGeneralEntertainment" runat="server" ConnectionString="<%$ ConnectionStrings:devHousingWebSiteConnectionString %>"

                        SelectCommand="SELECT * FROM [CableChannels] where channel_genre=1" 

                        onselected="sqlGenreGeneralEntertainment_Selected" ></asp:SqlDataSource>





 <asp:DataList runat="server" ID="dlGenreGeneralEntertainment" RepeatColumns="3"

                        DataKeyField="channel_id" DataSourceID="sqlGenreGeneralEntertainment" 

                        ItemStyle-Width="165" 

                        onitemdatabound="dlGenreGeneralEntertainment_ItemDataBound" 

                        ondatabinding="dlGenreGeneralEntertainment_DataBinding">







protected void dlGenreGeneralEntertainment_ItemDataBound(object sender, DataListItemEventArgs e)

    {

       

        if (e.Item.ItemType == ListItemType.Separator)

        {

            if (e.Item.ItemIndex >= indextoclear)

            {

                e.Item.Controls.Clear();

            }

        }

    }



protected void sqlGenreGeneralEntertainment_Selected(object sender, SqlDataSourceStatusEventArgs e)

    {

        recordCount = dlGenreGeneralEntertainment.Items.Count;

        if (recordCount > 1)

        {

            indextoclear = (recordCount / 2);

        }

        else

        {

            indextoclear = -1;

        }

    }

Open in new window

0
 
LVL 41

Expert Comment

by:guru_sami
ID: 33739357
get recordcount like this:

recordCount =e.AffectedRows;
0
 

Author Comment

by:auxploeb
ID: 33739385
ok, got that, thanks. Now how do I adapt this for my 3 column Datalist?
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 41

Expert Comment

by:guru_sami
ID: 33739432
do you have some screeshot of datalist that can explain how it's looking right now and how you want it to look. my wild guess is divide by 3 instead of 2..so try

indextoclear = (recordCount / 3);

or to be generic: indextoclear = (recordCount / DataList1.RepeatColumns);
0
 
LVL 41

Assisted Solution

by:guru_sami
guru_sami earned 500 total points
ID: 33739610
I think it will also depend on the RepeatDirection...looks like you have Vertical which is by default...
so it should be something like this:

 indextoclear = (recordCount / 3) * 2 + 1;

and your if will be:

if (e.Item.ItemIndex > indextoclear)
            {
                e.Item.Controls.Clear();
            }

Note: I think i will give you idea to play round.
0
 
LVL 41

Expert Comment

by:guru_sami
ID: 33739804
And what was wrong...the question or the suggestions provided?
0
 
LVL 41

Expert Comment

by:guru_sami
ID: 33771102
Though might not be exact solution, comments http:#33739188 and http:#33739610 were in right direction based on the info provided by OP.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

911 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

21 Experts available now in Live!

Get 1:1 Help Now