Becky Bloomwood

Becky Bloomwood

  • NA
  • 119
  • 285.8k

Drop down list problem for editing req in grid view

Feb 13 2011 10:49 PM
Hi, I am trying to do an edit req and when I click on the edit, one of the options is DDL. However, there is a prob. I am not sure of how to resolve it.
This is the business logic for the DDL:

 

protected void gvChecklist_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Footer)
{
DropDownList cmbStatus = (DropDownList)e.Row.FindControl("cmbStatus");
cmbStatus.DataSource = vrmdb.Get_Status();
cmbStatus.DataTextField = "status";
cmbStatus.DataValueField = "status";
cmbStatus.DataBind();
}
if (e.Row.RowType == DataControlRowType.DataRow)
{
DropDownList cmbNewStatus = (DropDownList)e.Row.FindControl("cmbNewStatus");
if (cmbNewStatus != null)
{
cmbNewStatus.DataSource = vrmdb.Get_Status();
cmbNewStatus.DataTextField = "status";
cmbNewStatus.DataValueField = "status";
cmbNewStatus.DataBind();
cmbNewStatus.SelectedValue = gvChecklist.DataKeys[e.Row.RowIndex].Values[1].ToString();
};
}
}
protected void gvChecklist_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Footer)
{
DropDownList cmbStatus = (DropDownList)e.Row.FindControl("cmbStatus");
cmbStatus.DataSource = vrmdb.Get_Status();
cmbStatus.DataTextField = "status";
cmbStatus.DataValueField = "status";
cmbStatus.DataBind();
}
if (e.Row.RowType == DataControlRowType.DataRow)
{
DropDownList cmbNewStatus = (DropDownList)e.Row.FindControl("cmbNewStatus");
if (cmbNewStatus != null)
{
cmbNewStatus.DataSource = vrmdb.Get_Status();
cmbNewStatus.DataTextField = "status";
cmbNewStatus.DataValueField = "status";
cmbNewStatus.DataBind();
cmbNewStatus.SelectedValue = gvChecklist.DataKeys[e.Row.RowIndex].Values[1].ToString();
};
}
}

This is the error:

 

Server Error in '/VRM_WebSite' Application.

Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index


Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index

Source Error:


Line 417:                    cmbNewStatus.DataValueField = "status";
Line 418:                    cmbNewStatus.DataBind();
Line 419:                    cmbNewStatus.SelectedValue = gvChecklist.DataKeys[e.Row.RowIndex].Values[1].ToString();
Line 420:                };
Line 421:            }

Source File: c:\Users\L31410\Desktop\Peggie\Peggie\Deployment Source\Phase 1\Deployment 25 Nov for StarHub\VS Projects Source\VRM_WebSite\app\vrm\ContractThreeGridView.aspx.cs    Line: 419

Stack Trace:


Thks for ur help all these while. I am grateful for it:)













 
 

Answers (4)