SqlConnection con = new SqlConnection(scon);
        SqlDataAdapter da = new SqlDataAdapter("select Question,Option1,Option2,Option3,Option4 from QuestionData", con);
        DataSet ds = new DataSet();
        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

Edited by __avd: Added [code] tags. Encase your code in: [code] and [/code] tags.

8 Years
Discussion Span
Last Post by __avd

>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();
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.