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
Solved

Hide a separator in a datalist ASP.Net

Posted on 2010-09-22
11
846 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

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 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

839 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