当我点击更新按钮时,我收到此错误 我的更新点击事件
protected void btnUpdate_Click(object sender, CommandEventArgs e)
{
int idx = Convert.ToInt32(e.CommandArgument);
GridViewRow gr = gvResTasks.Rows[idx];
当idx
值达到19时,它可以正常工作。当它大于19时,会发生此错误。
Updatebutton.aspx
<ItemTemplate>
<asp:Button runat="server" ID="btnUpdate" Text="Update" OnCommand="btnUpdate_Click" CommandArgument="<%# Container.DataItemIndex %>" />
<%--<asp:Button runat="server" ID="Button1" Text="Update" onclick="btnUpdate_Click" />--%>
</ItemTemplate>
updatebutton.aspx.cs
protected void btnUpdate_Click(object sender, CommandEventArgs e)
{
// int idx = Convert.ToInt32(e.CommandArgument);
int idx = Convert.ToInt32(e.CommandArgument);
GridViewRow gr = gvResTasks.Rows[idx];
Label hf = (Label)gr.FindControl("hdEmployeeID");
string sEmpID = hf.Text;
lblEmployeeID.Text = sEmpID;
lblEmployeeID2.Text = sEmpID;
int Rows = gvResTasks.Rows.Count;
for (int x = 0; x < Rows; x++)
{
GridViewRow tr = gvResTasks.Rows[x];
tr.CssClass = "WhiteBack";
}
ClearMessages();
gr.CssClass = "TealBack";
string sSubTaskID = gr.Cells[0].Text;
lblSubTaskID.Text = sSubTaskID;
lblSubTaskName.Text = @gr.Cells[1].Text;
LoadSubTaskInfo();
Single sProgress = 0;
Boolean bok = Single.TryParse(lblActualProgress.Text, out sProgress);
DateTime dPF = DateTime.Parse(lblPlannedFinish.Text);
if (dPF > DateTime.Now)
{
btnFinish.Enabled = false;
}
else if (dPF <= DateTime.Now)
{
if (sProgress >= 100)
{
btnFinish.Enabled = false;
}
else
{
btnFinish.Enabled = true;
}
//btnFinish.Enabled = true;
}
panelUpdate.CssClass = "float";
panelUpdate.Visible = false;
if (gr.Cells[7].Text != "True")
{
panelUpdate.Visible = true;
}
}
答案 0 :(得分:0)
您正在尝试从gvResTasks中获取一个值,该值位于gridView中高于其中行数的位置。因此索引超出范围的错误。