Solved

Hide a separator in a datalist ASP.Net

Posted on 2010-09-22
11
843 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

746 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

12 Experts available now in Live!

Get 1:1 Help Now