Click here to Skip to main content
15,914,642 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My code is something like this:
ASP.NET
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="p1.aspx.cs" Inherits="Puu1" %>


<html xmlns="http://www.w3.org/1999/xhtml">
<head  runat="server">
    <title>Puu1</title>
</head>
<body>
    <form id="form1"  runat="server">
                                   
                                        
Question  :   
                                       
    </form>
</body>
</html>

Code behind file:
C#
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Web.Configuration;
using System.Data.SqlClient;
public partial class Puu1 : System.Web.UI.Page
{

    PagedDataSource objDs = new PagedDataSource();

    public int CurrentPage
    {
        get
        {
            object o = this.ViewState["_CurrentPage"];
            if (o == null)
                return 0;
            else
                return (int)o;
        }
        set
        {
            this.ViewState["_CurrentPage"] = value;
        }

    }


    protected void Page_Load(object sender, EventArgs e)
    {

        if (!IsPostBack)
        {
            itemsGet();
        }
    }

    protected void itemsGet()
    {
        PagedDataSource objDs = new PagedDataSource();
        DataView dv = (DataView)SqlDataSource1.Select(DataSourceSelectArguments.Empty);
        objDs.DataSource = dv;
        objDs.AllowPaging = true;
        objDs.PageSize = 5;
        objDs.CurrentPageIndex = CurrentPage;
        lblCurrentPage.Text = "Page:" + (CurrentPage + 1).ToString() + " Of " + objDs.PageCount.ToString();
        cmdPrev.Enabled = !objDs.IsFirstPage;
        cmdNext.Enabled = !objDs.IsLastPage;
        dlQuestions.DataSource = objDs;
        dlQuestions.DataBind();

    }



    protected void cmdNext_Click1(object sender, EventArgs e)
    {
        try
        {

            CurrentPage += 1;
            itemsGet();
        }
        catch (Exception ex)
        {

        }

    }
    protected void cmdPrev_Click(object sender, EventArgs e)
    {
        try
        {
            CurrentPage -= 1;
            itemsGet();
        }
        catch (Exception ex)
        {

        }
    }




    protected void dlQuestions_ItemCommand(object source, DataListCommandEventArgs e)
    {
        foreach (DataListItem item in dlQuestions.Items)
        {
            RadioButton RB = item.FindControl("rdb1") as RadioButton;
            if (RB != null && RB.Text != null)
            {

                lblanswer.Text= RB.Text;//for testing purpose only
            }
        }
    }
}
Posted
Updated 11-Jan-12 18:09pm
v2
Comments
Rockstar_G 12-Jan-12 2:04am    
dlquestions_itemCommand() event not firing........

1 solution

C#
protected void dlQuestions_ItemCommand(object source, DataListCommandEventArgs e)
{
    RadioButton RB = (RadioButton)e.Item.FindControl("rdb1");
    if (RB != null && RB.Text != null)
    {
        lblanswer.Text = RB.Text;//for testing purpose only
    }
}


Try This one....
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900