ashab27 0 Newbie Poster

Hi,
I am getting so much of problem on DataList
This is my code in asp.net

<asp:Button ID="NextQusButton" runat="server" onclick="NextQusButton_Click"
Text=" Next " onclientclick="javascript: return validate()" Height="26px" />
</p>
<p>
<asp:DataList ID="ItemsList" runat="server" DataSourceID="SqlDataSource1"
onitemcommand="ItemsList_ItemCommand"
Visible="False">
<ItemTemplate>
Question: <%#Container.ItemIndex %>
<%# DataBinder.Eval(Container.DataItem, "Question")%>
<br />
<asp:CheckBox ID="CheckBox1" runat="server" />
<%# DataBinder.Eval(Container.DataItem, "Option1")%>
<br />
<asp:CheckBox ID="CheckBox2" runat="server" />
<%# DataBinder.Eval(Container.DataItem, "Option2")%>
<br />
<asp:CheckBox ID="CheckBox3" runat="server" />
<%# DataBinder.Eval(Container.DataItem, "Option3")%>
<br />
<asp:CheckBox ID="CheckBox4" runat="server" />
<%# DataBinder.Eval(Container.DataItem, "Option4")%>
<br />
<br />
</ItemTemplate>
</asp:DataList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:onlineexamdbConnectionString %>"
SelectCommand="SELECT [Question], [Option1], [Option2], [Option3], [Option4] FROM [QuestionData]">
</asp:SqlDataSource>

and in .aspx.cs file is this............
using System.Data.SqlClient;

public partial class QuestionPage : System.Web.UI.Page
{
string scon = "Data Source=RBWORKSTATION2\\SQLEXPRESS;Initial Catalog=onlineexamdb;Integrated Security=True;MultipleActiveResultSets=true";
SqlDataAdapter da;
SqlCommand cmd;
DataSet ds;
public string query;
//int questiondata = Global.QuestionData;
ArrayList myArrayList = new ArrayList();
SqlDataReader dr;
DataTable dt = new DataTable();

protected void Page_Load(object sender, EventArgs e)
{


SqlConnection con = new SqlConnection(scon);
da = new SqlDataAdapter("select Question,Option1,Option2,Option3,Option4 from QuestionData", con);
ds = new DataSet();
da.Fill(ds);
ItemsList.DataSource = dr;
ItemsList.DataBind();
}
protected void NextQusButton_Click(object sender, EventArgs e)
{

ItemsList.Visible = true;
}

My ItemList means its DataList and dr is SqlDataReader dr;
I have one table in database ,which conation 5 column.Question,Option1,2,3,4.
from this code i can show my hole data but I want to do that on page load my 1st question should be display and when i will click on next button that 2nd question and after click on next button 3rd question should be display.I can not do it please give some help.
I also tried this code also
SqlConnection con = new SqlConnection(scon); con.Open(); SqlDataAdapter da = new SqlDataAdapter("select Question,Option1,Option2,Option3,Option4 from QuestionData", con); DataSet ds = new DataSet(); da.Fill(ds); foreach (DataColumn dc in ds.Tables[0].Columns) { foreach (DataRow dr in ds.Tables[0].Rows) { Questionlable.Text = dr[0].ToString(); OptionList.Items[0].Text = dr[1].ToString(); OptionList.Items[1].Text = dr[2].ToString(); OptionList.Items[2].Text = dr[3].ToString(); OptionList.Items[3].Text = dr[4].ToString(); } } SqlConnection con = new SqlConnection(scon);
con.Open();
SqlDataAdapter da = new SqlDataAdapter("select Question,Option1,Option2,Option3,Option4 from QuestionData", con);
DataSet ds = new DataSet();
da.Fill(ds);
foreach (DataColumn dc in ds.Tables[0].Columns)
{
foreach (DataRow dr in ds.Tables[0].Rows)
{
Questionlable.Text = dr[0].ToString();
OptionList.Items[0].Text = dr[1].ToString();
OptionList.Items[1].Text = dr[2].ToString();
OptionList.Items[2].Text = dr[3].ToString();
OptionList.Items[3].Text = dr[4].ToString();
}
}
but it also not working like that , which i want
Please ,Please give me help.
Thank you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.