我尝试通过下拉列表提交文档 当管理员在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)
ERROR
指数超出范围。必须是非负数且小于集合的大小。 参数名称:index
任何解决方案?
答案 0 :(得分:-1)
看看你的
GrdFileApprove.DataKeys[row.RowIndex]["ApproveID"]
我在这一行放了一个断点,检查你的GrdFileApprove.DataKeys,看看你的row.RowIndex值和“ApproveID”是否有效,可以访问DataKeys集合。