Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3759694
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T10:21:22+00:00 2026-05-19T10:21:22+00:00

I am using listview and datapager for display. I use two level of listview,

  • 0

I am using listview and datapager for display. I use two level of listview, where inner listview item can be 6 types. I use my own datasource. I only need to display 1 inner listviewitem per page. It display each page correctly, but page number is not set right, eg, when 2nd page (other as well) is click, 2nd page number is not disabled while 1st page number is still disabled. Here is the code:

   <div style="margin: 10px;">
        <asp:ListView ID="rptExercise2" runat="server" 
            ItemPlaceholderID="itemPlaceHolder1" OnItemDataBound="ExerciseBound" OnPagePropertiesChanging="ChangeExercise">
            <LayoutTemplate>      
                <asp:PlaceHolder ID="itemPlaceHolder1" runat="server" />
            </LayoutTemplate>

            <ItemTemplate>
            <h2><asp:Label ID="lbName" runat="server" /></h2>
            <asp:ListView ID="rptContent2" runat="server" ItemPlaceholderID="itemPlaceHolder2" OnItemDataBound="ContentBound">
                <LayoutTemplate>      
                    <asp:PlaceHolder ID="itemPlaceHolder2" runat="server" />
                </LayoutTemplate>

                <ItemTemplate>
                    <div style="padding: 5px;" >                               
                        <div>
                        <asp:Label ID="lbID" runat="server" Text='<%# Eval("ID") %>' Visible="false" />

                        <asp:Label ID="lbWrapper" runat="server" Text='<%# Eval("Wrapper") %>' Visible="false" />

                        <asp:Label ID="lbAudioQuestion" runat="server" Visible="false" />

                        <div style="text-align: right;"><asp:Label ID="lbAudioAnswer" runat="server" Visible="false" /></div>

                        <div style="text-align: right;"><asp:TextBox ID="tbAnswer" runat="server" TextMode="MultiLine" CssClass="tb" Width="50%" Height="60" Visible="false" /></div>

                        <div style="margin-left: 20px;"><asp:RadioButtonList ID="rblChoice" runat="server" Visible="false" /></div>                               
                        </div>                                
                    </div>
                </ItemTemplate>
            </asp:ListView>

            <asp:Panel ID="pnFeedback" runat="server" Visible="false" CssClass="Feedback">
                <div style="margin: 10px;">
                    <div style="float: left;">
                    Score: <br /><asp:TextBox ID="tbScore" runat="server" CssClass="tb" Width="40" /> / <asp:Label ID="lbScore" runat="server" /></div>
                    </div>
                    <asp:Label ID="lbResultID" runat="server" Visible="false" />
                    <div style="float: left;">
                    Feedback<br />
                    <asp:TextBox ID="tbFeedback" runat="server" TextMode="MultiLine" CssClass="tb" Width="200" Height="60" />
                    </div>

                    <div style="float: left;">
                    Recording<br />
                    <asp:Label ID="lbFeedbackAudio" runat="server" />
                    </div>
                    <br style="clear: both;" />
                </div>
            </asp:Panel>

            </ItemTemplate>
            <EmptyItemTemplate>
                <div>
                    Sorry, no exercise is found for this lesson.
                </div>
            </EmptyItemTemplate>

        </asp:ListView>


        <asp:DataPager ID="DataPager" runat="server" PagedControlID="rptExercise2" 
            PageSize="1">
            <Fields>
                <asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True" 
                    ShowNextPageButton="False" ShowPreviousPageButton="False" />
                <asp:NumericPagerField ButtonCount="10" ButtonType="Button" />
                <asp:NextPreviousPagerField ButtonType="Button" ShowLastPageButton="True" 
                    ShowNextPageButton="False" ShowPreviousPageButton="False" />
            </Fields>
        </asp:DataPager>  

public partial class MyPracClass : System.Web.UI.Page
{
    // Current page number
    int i = 0;

    protected classLessons les;
    protected classExercises exc;
    protected List<classExercises> exercises;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request["LessonID"] == null)
        {
            return;
        }

        classLessons les = new classLessons(Convert.ToInt32(Request["LessonID"]));
        exc = new classExercises();
        exercises = exc.GetExercisesByLessonID(les.ID);

        if (!IsPostBack)
        {
            lbLessonName.Text = les.Name;
            lbDescription.Text = les.Description;
            //SetPageNumber();

            rptExercise2.DataSource = exercises;
            rptExercise2.DataBind();
        }
    }

    protected void ExerciseBound(object sender, ListViewItemEventArgs e)
    {
        if (e.Item.ItemType == ListViewItemType.DataItem)
        {
            ListViewDataItem item = (ListViewDataItem)e.Item;

            Label lbName = (Label)item.FindControl("lbName");
            string excName = "Exercise " + (i+1) + ": " + exercises[i].Subject;
            lbName.Text = excName;

            Label lbFeedbackAudio = (Label)item.FindControl("lbFeedbackAudio");
            classContent ct = new classContent();
            string test = "exercise" + exercises[i].ID + "student" + Session["StudentID"] + "feedback";
            lbFeedbackAudio.Text = ct.GetPlayingString("exercise" + exercises[i].ID + "student" + Session["StudentID"] + "feedback");

            ListView rptContent2 = (ListView)item.FindControl("rptContent2");
            Panel pnFeedback = (Panel)item.FindControl("pnFeedback");

            if (exercises[i] != null && rptContent2 != null)
            {
                classContent cct = new classContent();

                rptContent2.DataSource = cct.GetContentByExerciseID(exercises[i].ID);
                rptContent2.DataBind();
            }

            var result = new classResults();

            result.GetResultByExerciseID(Convert.ToInt32(exercises[i].ID));

            if (result.ID > 0)
            {
                pnFeedback.Visible = true;
                Label lbID = (Label)item.FindControl("lbResultID");
                Label lbScore = (Label)item.FindControl("lbScore");
                lbScore.Text = exercises[i].Score.ToString();
                TextBox tbScore = (TextBox)item.FindControl("tbScore");
                TextBox tbFeedback = (TextBox)item.FindControl("tbFeedback");

                lbID.Text = result.ID.ToString();
                tbScore.Text = result.Score.ToString();
                tbFeedback.Text = result.Feedback;
            }
        }
    }

    protected void ChangeExercise(object sender, PagePropertiesChangingEventArgs e)
    {
        // Get current page number
        i = e.StartRowIndex / e.MaximumRows;

        rptExercise2.DataSource = exercises;
        rptExercise2.DataBind();
    }

    //protected void DataPager_PreRender(object sender, EventArgs e)
    //{
    //    // Get current page number
    //    //i = e.StartRowIndex / e.MaximumRows;

    //    rptExercise2.DataSource = exercises;
    //    rptExercise2.DataBind();
    //}

    protected void ContentBound(object sender, ListViewItemEventArgs e)
    {
        if (e.Item.ItemType == ListViewItemType.DataItem)
        {
            ListViewDataItem dataItem = (ListViewDataItem)e.Item;
            var qry = (classContent)dataItem.DataItem;

            Label lbAudioQuestion = (Label)e.Item.FindControl("lbAudioQuestion");
            Label lbAudioAnswer = (Label)e.Item.FindControl("lbAudioAnswer");
            Label lbWrapper = (Label)e.Item.FindControl("lbWrapper");
            TextBox tbAnswer = (TextBox)e.Item.FindControl("tbAnswer");
            RadioButtonList rblChoice = (RadioButtonList)e.Item.FindControl("rblChoice");

            switch (qry.Type)
            {
                case classContent.ContentType.AudioQuestion:
                    lbAudioQuestion.Visible = true;
                    lbAudioQuestion.Text = qry.GetPlayingString(qry.Wrapper);
                    break;
                case classContent.ContentType.TextQuestion:
                    lbWrapper.Visible = true;
                    break;
                case classContent.ContentType.VideoQuestion:
                    lbWrapper.Visible = true;
                    break;
                case classContent.ContentType.AudioAnswer:
                    lbAudioAnswer.Visible = true;
                    lbAudioAnswer.Text = qry.GetRecordingString("content" + qry.ID + "student" + Session["StudentID"]);
                    break;
                case classContent.ContentType.TextAnswer:
                    tbAnswer.Visible = true;
                    break;
                case classContent.ContentType.ChoiceAnswer:
                    rblChoice.DataSource = qry.GetChoiceOptions(qry.ID);
                    rblChoice.DataTextField = "Value";
                    rblChoice.DataValueField = "IsAnswer";
                    rblChoice.DataBind();
                    rblChoice.Visible = true;
                    break;
                default: break; ;
            }

            classAnswers ans = new classAnswers();

            var contentAnswer = ans.GetAnswerByContentID(qry.ID);

            if (contentAnswer.ID > 0)
            {
                switch (qry.Type)
                {
                    case classContent.ContentType.TextAnswer:
                        tbAnswer.Text = contentAnswer.Answer;
                        break;
                    case classContent.ContentType.ChoiceAnswer:
                        rblChoice.SelectedIndex = Convert.ToInt32(contentAnswer.Answer);
                        break;
                    default: break; ;
                }
            }

        }

    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T10:21:23+00:00Added an answer on May 19, 2026 at 10:21 am

    This article tells you everything you might need about utilizing a DataPager control https://web.archive.org/web/20201202213937/https://www.4guysfromrolla.com/articles/011310-1.aspx (see the last section of the article)

    The article clearly explains about applying/modifying individual page numbers in the paging area. So I think you will simply have to write a CSS class to disable the current page number’s button/link and enable the remaining page numbers.

    Hope this helps…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using a ListView in which only one item can be checked at
Can I have some tutorial/sample code of using datapager in a asp.net listview control?
I am using a datapager inside a nested Listview succesfully. When only one record
I am using the ListView Control with the following datasource List<MyObject> On my listview
i want to display some information in a listview using the GridView. i have
I have a listview with two columns and I'm using a context menu to
I am using a ListView and DataPager in my web project for pagination. It
I am using ListView/DataPager. For performance reasons I page my results at database, using
i ma using am listview and datapager control. in my list view i have
I have a standard ASP.Net DataPager with a standard ListView (using a DataTable as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.