0

Question テーブルの Questions の列値を配列に格納するメソッドを作成しましたが、ボタン クリック イベントで 1 つずつラベルに表示したいと考えました。

public ArrayList BindDataToArray()
{
    ArrayList list = new ArrayList();
    DataTable dt = new DataTable();
    con = new SqlConnection(str);
    cmd = new SqlCommand("select Question from  Questions", con);
    con.Open();
    adp = new SqlDataAdapter(cmd);
    adp.Fill(dt);

    foreach (DataRow dtrow in dt.Rows)
    {
        list.Add(dtrow);
    }
    return list;
}
4

4 に答える 4

0

asp.net のgridviewコントロールを探しているようです。
http://www.dotnetfunda.com/articles/article1594-how-to-populate-gridview-from-code-behind.aspx

于 2013-04-18T06:25:59.337 に答える
0

これを試して....

<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] as string; //Label in which u want to 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 from  Questions", con);
    con.Open();
    adp = new SqlDataAdapter(cmd);
    adp.Fill(dt);

    foreach (DataRow dtrow in dt.Rows)
    {
        list.Add(dtrow["Question"].ToString());
    }
    return list;
}
于 2013-04-18T06:26:29.010 に答える
0
// in Aspx Page
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" 
            CommandArgument="1" /><asp:Label
           ID="Label1" runat="server" Text="Label"></asp:Label>
//in Aspx.cs

        protected void Button1_Click(object sender, EventArgs e)
        {
            ArrayList list = new ArrayList();
            list = BindDataToArray();
            int I = (Convert.ToInt32(Button1.CommandArgument.Count()));
            //int I = (Convert.ToInt32(Button1.CommandArgument));
            if (I < list.Count)
            {
                Label1.Text = list[I] as string; //Label in which u want to 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(con);
            SqlCommand cmd = new SqlCommand("SELECT SurveyName FROM tblSurveyName", con);
            con.Open();
            SqlDataAdapter adp = new SqlDataAdapter(cmd);
            adp.Fill(dt);

            foreach (DataRow dtrow in dt.Rows) { list.Add(dtrow["SurveyName"].ToString()); }
            return list;
        }
于 2013-07-29T20:46:54.933 に答える