|
-
August 2nd, 2007, 08:52 AM
#1
Specified argument was out of the range of valid values. Parameter name
Hi All,
I am using a DropDownList with 4 static items namely Pending, Deffered, Settled and Rejected as they are static in actual use and won't change.
This DDL is placed in a template field of a DataGrid. The table which is used to fill the DataGrid contain a field namely TagStatus which contains the status of the customer as Pending, Deffered etc..
One requirement is that when the DataGrid shows the customer's data , the DropDowlList's selected value should be the one in the database while the DropDownList should also contain other static fields for updating the customer status.
So what i do is that after Populating the DataGrid from the table, i loop through the items of the DataGrid and set the SelectedValue Property of each DDL as follows
PHP Code:
private void btnSearch_Click(object sender, System.EventArgs e)
{
string ProcName = "GetClaimedBorrowers"; //Stored Procedure Name
string ClaimNo = txtClaimNo.Text.Trim(); // the Key used for filtering
DataAccess objData = new DataAccess(); //Class for Data Access
DataSet ClaimData = new DataSet();
try
{
objData.openConnection();
objData.ProcName = ProcName;
objData.CreateCommand();
objData.Parameters("@ClaimNo",SqlDbType.VarChar,25,ClaimNo);
objData.createAdapter().Fill(ClaimData);
gridAdjustments.DataSource = ClaimData.Tables[0];
gridAdjustments.DataBind();
AssignStatus(ClaimData);
}
catch(Exception ex)
{
lblMessage.Text = ex.Message;
}
finally
{
objData.CloseConnection();
objData.DisposeConnection();
ClaimData.Dispose();
}
}
private void AssignStatus(DataSet dsCreditors)
{
int rows = dsCreditors.Tables[0].Rows.Count;
for(int i = 0; i < rows; i++)
{
DropDownList ddl = gridAdjustments.Items[i].FindControl("ddlStatus") as DropDownList;
ddl.SelectedValue = dsCreditors.Tables[0].Rows[i]["TagStatus"].ToString().Trim();
}
}
// As i told u that static members of the DDL are
//
// 1. Pending
// 2. Settled
// 3. Rejected
// 4. Deffered
//
//
// I Receive error as "Specified argument was out of
// the range of valid values. Parameter name: Settled"
//
// This errors occurs when the AssignStatus() function is executed
//
//
so can u help me out of this problem...... and is there some other proper way to assign retrieved values to DDLs without looping htrough all items
Any help is greatly appeciated
TC
-
August 3rd, 2007, 11:48 AM
#2
Re: Specified argument was out of the range of valid values. Parameter name
i think the first thing i would try is this
Code:
//change this line
int rows = dsCreditors.Tables[0].Rows.Count;
//to this line
DropDownList ddl = gridAdjustments.Items[i].FindControl("ddlStatus") as DropDownList;
int rows = ddl.Rows.Count
because your setting the length as the # of rows returned from your data table not the actual drop down list control. Its probably got one extra row returned and thats why your getting that out of bounds error.
hth,
mcm
rate my posts!
mcm
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|