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();
             }
        }

This is the code

I have table QuestionData with 5 column and 60 rows'
I am using this code in the button
I want to take my 1st column data in Questionlable.Text and and
2nd column data in the OptionList.Items[0].Text , like that
but here when i do this then i am getting last row value
not first row.
I want that when i click on button then it should be show all data one by one.
i am doing this ASP.NET web application.
I used the Sqldatareader also but same out .how can i get the frist column value one by one in the lable

>but here when i do this then i am getting last row value
not first row.

In above code snippet, you are trying to assign values (approx. 60 rows) from datatable to a single textbox and optionlist control - and, that is a problem.

To solve your problem, you must have to use/learn the complex controls like - GridView, DataList, and Repeater. Adding controls dynamically might be good option.

Have a look at sample that add controls runtime,

foreach (DataRow dr in ds.Tables[0].Rows)
            {
                TextBox tx=new TextBox();
                tx.Text = dr[0].ToString();
                RadioButtonList opt=new RadioButtonList();
                opt..Items[0].Text = dr[1].ToString();
                opt.Items[1].Text = dr[2].ToString();
                opt.Items[2].Text = dr[3].ToString();
                opt.Items[3].Text = dr[4].ToString();
                form1.Controls.Add(tx);
                form1.Controls.Add(opt);
             }
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.