This is a migrated thread and some comments may be shown as answers.

Radgrid Insert Problem...

1 Answer 41 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Vivek Tyagi
Top achievements
Rank 1
Vivek Tyagi asked on 30 Oct 2011, 06:46 PM

Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
error @ line 4 I have marked it..

M using webusercontrol to insert Value

 

protected void RadGrid1_UpdateCommand(object sender, GridCommandEventArgs e)
        {
            GridEditableItem editeditem = (GridEditableItem)e.Item;
            UserControl userControl = (UserControl)e.Item.FindControl(GridEditFormItem.EditFormUserControlID);
 
            string ID1 = editeditem.OwnerTableView.DataKeyValues[editeditem.ItemIndex]["ID"].ToString();
 
            //HiddenField hddn = (HiddenField)userControl.FindControl("HiddenField1");
 
            TextBox city1 = (TextBox)userControl.FindControl("TextBox1");
            DropDownList ddpl1 = (DropDownList)userControl.FindControl("DropDownList1");
 
            string updatequery = String.Format("UPDATE MST_City set City='{0}', StateID='{1}' where ID='{2}'", city1.Text, ddpl1.SelectedValue, ID1);
            con.Open();
            using (SqlCommand sql = new SqlCommand() { CommandText = updatequery, Connection = con })
            {
                sql.ExecuteNonQuery();
            }
            con.Close();
 
        }

1 Answer, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 30 Oct 2011, 07:35 PM
Hello,

In the insert time, there is not any ID is there so you got this error.

for insert why are you not used insertCommand event.

let me know if any concern.

Thanks,
Jayesh Goyani
Tags
Grid
Asked by
Vivek Tyagi
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Share this question
or