c# - How to Bind column of a table in array and display result one by one on button click event? -


i have created method store column value of questions question table array , wanted display in label 1 one on button click event.

public arraylist binddatatoarray() {     arraylist list = new arraylist();     datatable dt = new datatable();     con = new sqlconnection(str);     cmd = new sqlcommand("select question  questions", con);     con.open();     adp = new sqldataadapter(cmd);     adp.fill(dt);      foreach (datarow dtrow in dt.rows)     {         list.add(dtrow);     }     return list; } 

try this....

<asp:button id="button1" runat="server" text="button" onclick="button1_click"               commandargument="0" />//defination of button on aspx page  protected void button1_click(object sender, eventargs e) {      arraylist list = new arraylist();      list=binddatatoarray();      int i=( convert.toint32(button1.commandargument));      if (i < list.count)      {           label1.text = list[i] string; //label in u want show message           button1.commandargument = (i + 1).tostring();      }      else      {          label1.text = "end of list";          button1.enabled = false;      } }  public arraylist binddatatoarray() {     arraylist list = new arraylist();     datatable dt = new datatable();     con = new sqlconnection(str);     cmd = new sqlcommand("select question  questions", con);     con.open();     adp = new sqldataadapter(cmd);     adp.fill(dt);      foreach (datarow dtrow in dt.rows)     {         list.add(dtrow["question"].tostring());     }     return list; } 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -