我從數據庫中gridview
textbox
檢索數據的大小在數據庫中的兩個行,但不能取,錯誤:索引超出範圍。必須爲非負且小於集合的
string sr_no;
int rowIndex = 0;
for (int i = 1; i <= dt1.Rows.Count; i++)
{
//extract the TextBox values
TextBox box1 = (TextBox)Gridview1.Rows[rowIndex].Cells[1].FindControl("TextBox1");
TextBox box2 = (TextBox)Gridview1.Rows[rowIndex].Cells[2].FindControl("TextBox2");
TextBox box3 = (TextBox)Gridview1.Rows[rowIndex].Cells[3].FindControl("TextBox3");
TextBox box4 = (TextBox)Gridview1.Rows[rowIndex].Cells[4].FindControl("TextBox4");
TextBox box5 = (TextBox)Gridview1.Rows[rowIndex].Cells[5].FindControl("TextBox5");
TextBox box6 = (TextBox)Gridview1.Rows[rowIndex].Cells[6].FindControl("TextBox6");
TextBox box7 = (TextBox)Gridview1.Rows[rowIndex].Cells[7].FindControl("TextBox7");
TextBox box8 = (TextBox)Gridview1.Rows[rowIndex].Cells[8].FindControl("TextBox8");
box1.Text = dt1.Rows[i-1]["RD_PS_APPLab_Parameter"].ToString();
sr_no = dt1.Rows[i-1]["RD_SR_No"].ToString();
box2.Text = dt1.Rows[i-1]["Test"].ToString();
box3.Text = dt1.Rows[i-1]["Test_Condition"].ToString();
box4.Text = dt1.Rows[i-1]["Method"].ToString();
box5.Text = dt1.Rows[i-1]["CTQ"].ToString();
box6.Text = dt1.Rows[i-1]["Specification_RD_PS_AppLab"].ToString();
box7.Text = dt1.Rows[i-1]["UOM"].ToString();
box8.Text = dt1.Rows[i-1]["Remarks"].ToString();
rowIndex++;
}
我收到錯誤
Error: Index was out of range. Must be non-negative and less than the size of the collection
你的排是否有9格?你研究了什麼來解決你的問題? – Sayse
您的視圖是否比行數多一行?第0行是什麼?什麼是在網格視圖中創建行? –
是每行都有9個單元 – Sadhana