Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Hide a separator in a datalist ASP.Net

Posted on 2010-09-22
11
Medium Priority
?
853 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 2
11 Comments
 
LVL 41

Accepted Solution

by:
guru_sami earned 2000 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
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 

Author Comment

by:auxploeb
ID: 33739385
ok, got that, thanks. Now how do I adapt this for my 3 column Datalist?
0
 
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 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Screencast - Getting to Know the Pipeline

597 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