我用for循环去取出GridView的行,可是为什么,第一行的索引总是跑到第二行,第二行跑到第三行,第三行跑到第四行,以此类推,最后总是最后的一行取不出值,这是为神马?
代码如下:这是在RowDataBound中写的:
if (e.Row.RowType == DataControlRowType.DataRow)
{
string strID = "";
int intDetailRecordCount = dvList.Rows.Count;
if (intDetailRecordCount != 0)
{
for (int i = 0; i < intDetailRecordCount; i++)
{
strID = dvList.Rows[i].Cells[1].Text;
} //GridView gv = (GridView)e.Row.FindControl("dvList1");
//string strsql = "SELECT * FROM t_PaiGong_Item_Detail WHERE ItemID='" + strID + "'"; //DataTable dt = DBHelp.ReturnDataTable(strsql, "t_PaiGong_Item_Detail");
//gv.DataSource = dt;
//gv.DataBind();
Response.Write("<script>alert('" + strID + "');</script>");
}
}
代码如下:这是在RowDataBound中写的:
if (e.Row.RowType == DataControlRowType.DataRow)
{
string strID = "";
int intDetailRecordCount = dvList.Rows.Count;
if (intDetailRecordCount != 0)
{
for (int i = 0; i < intDetailRecordCount; i++)
{
strID = dvList.Rows[i].Cells[1].Text;
} //GridView gv = (GridView)e.Row.FindControl("dvList1");
//string strsql = "SELECT * FROM t_PaiGong_Item_Detail WHERE ItemID='" + strID + "'"; //DataTable dt = DBHelp.ReturnDataTable(strsql, "t_PaiGong_Item_Detail");
//gv.DataSource = dt;
//gv.DataBind();
Response.Write("<script>alert('" + strID + "');</script>");
}
}
為什麼寫在for循環外面?
if (e.Row.RowType == DataControlRowType.DataRow)
{
string strID = e.Row.Cells[1].Text;
Response.Write("<script>alert('" + strID + "');</script>");
}