当管理员在gridview中选择批准/拒绝一次然后单击提交按钮然后执行操作时,我尝试通过下拉列表提交文档
protected void Button1_Click(object sender, EventArgs e)
{
//foreach (GridViewRow row in GrdFileApprove.Rows)
//{
// //If row in Datarow then go ahead and find the control
// if (row.RowType == DataControlRowType.DataRow)
// {
// DropDownList DropDownListcontrol = row.FindControl("DropDownList4") as DropDownList;
// }
//}
string connStr
ConfigurationManager.ConnectionStrings["mydms"].ConnectionString;
SqlConnection mySQLconnection = new SqlConnection(connStr);
if (mySQLconnection.State == ConnectionState.Closed)
{
mySQLconnection.Open();
}
// Sql Command Object
//SqlCommand mySqlCommand;
DropDownList drdList;
foreach (GridViewRow row in GrdFileApprove.Rows)
{
drdList = (DropDownList)
(GrdFileApprove.Rows[row.RowIndex].Cells[1].FindControl("DropDownList4"));
if (GrdFileApprove.DataKeys[row.RowIndex]["ApproveID"].ToString() !=
drdList.SelectedValue)
{
SqlCommand cmd = new SqlCommand("approved", mySQLconnection);
}
}
if (mySQLconnection.State == ConnectionState.Open)
{
mySQLconnection.Close();
}
它告诉我这一行的错误
if (GrdFileApprove.DataKeys[row.RowIndex]["ApproveID"].ToString() !=
drdList.SelectedValue)
错误
指数超出范围。必须是非负数且小于集合的大小。参数名称:索引
任何解决方案?