0

当管理员在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) 

错误

指数超出范围。必须是非负数且小于集合的大小。参数名称:索引

任何解决方案?

4

1 回答 1

-1

看看你的

GrdFileApprove.DataKeys[row.RowIndex]["ApproveID"]

我会在这一行中放置一个断点并检查您的 GrdFileApprove.DataKeys 并查看您的 row.RowIndex 值和“ApproveID”是否可以使用 DataKeys 集合进行访问。

于 2013-10-07T17:57:55.883 回答