我正在使用 gridview 行命令编辑和删除。当我单击那些特定行数据显示在文本框上的链接时,如前所述。
第一个循环正在工作,但e.CommandName == "deletevalue"
显示错误
指数超出范围。必须是非负数且小于集合的大小
protected void GrdBuilding_RowCommand(object sender, GridViewCommandEventArgs e)
{
int index = Convert.ToInt32(e.CommandArgument);
if (e.CommandName == "editvalue")
{
TxtBuildingid.Text = GrdBuilding.Rows[index].Cells[1].Text;
TxtBuildingCode.Text = GrdBuilding.Rows[index].Cells[2].Text;
TxtBuildingName.Text = GrdBuilding.Rows[index].Cells[3].Text;
DrpBuilding.Text = GrdBuilding.Rows[index].Cells[4].Text;
if (GrdBuilding.Rows[index].Cells[5].Text.ToString() == "True")
{
ChkisActive.Checked = true;
}
else
{
ChkisActive.Checked = false;
}
BtnSave.Text = "Update";
}
else if (e.CommandName == "deletevalue")
{
TxtBuildingid.Text = GrdBuilding.Rows[index].Cells[1].Text;
TxtBuildingCode.Text = GrdBuilding.Rows[index].Cells[2].Text;
TxtBuildingName.Text = GrdBuilding.Rows[index].Cells[3].Text;
DrpBuilding.Text = GrdBuilding.Rows[index].Cells[4].Text;
if (GrdBuilding.Rows[index].Cells[5].ToString() == "True")
{
ChkisActive.Checked = true;
}
else
ChkisActive.Checked = false;
}
BtnSave.Text = "Delete";
}