値を取得し、データベースから gridview にバインドしたい
行数に基づいて、コントロールを動的に追加したい
コード:
私のテーブルには2行ありますが、以下のコードを使用すると2行目の値しか取得できません
protected void Gridview1_RowDataBound(object sender, GridViewRowEventArgs e)
{
int rowIndex = 0;
OleDbCommand cmd = new OleDbCommand("select activities,monday,tuesday,wednesday,thursday,friday,saturday,sunday from activity_values where week = '" + weekNumNow + "' and emp_id = (select emp_id from emp_master where username = '" + username + "')", DbConnection);
// DbConnection.Open();
OleDbDataReader dr1 = cmd.ExecuteReader();
while (dr1.Read())
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//find the control
DropDownList drop1 = e.Row.FindControl("dropActivities") as DropDownList;
TextBox box1 = e.Row.FindControl("TextBox1") as TextBox;
TextBox box2 = e.Row.FindControl("TextBox2") as TextBox;
TextBox box3 = e.Row.FindControl("TextBox3") as TextBox;
TextBox box4 = e.Row.FindControl("TextBox4") as TextBox;
TextBox box5 = e.Row.FindControl("TextBox5") as TextBox;
TextBox box6 = e.Row.FindControl("TextBox6") as TextBox;
TextBox box7 = e.Row.FindControl("TextBox7") as TextBox;
drop1.Text = dr1[0].ToString();
box1.Text = dr1[1].ToString();
box2.Text = dr1[2].ToString();
box3.Text = dr1[3].ToString();
box4.Text = dr1[4].ToString();
box5.Text = dr1[5].ToString();
box6.Text = dr1[6].ToString();
box7.Text = dr1[7].ToString();
}
rowIndex++;
}
}
何か案は?前もって感謝します