السلام عليكم
اخواني الاحبة لقد حاولت حذف row من خلال خاصية checbox في Gridview
ولكن للاسف لم تصلح معي فارجوا من الاخوة الافادة فان الخير سيعم الجميع باذن الله
</FONT></P> <P align=left><FONT size=3>SqlConnection conn = new SqlConnection();
SqlCommand cmd = new SqlCommand();
SqlParameter p = new SqlParameter();
conn.ConnectionString = "Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\Data.mdf;Integrated Security=True;User Instance=True;";
CheckBox box = new CheckBox();
foreach (GridViewRow orow in GridView1.Rows)
{
box = (CheckBox)orow.FindControl("CheckBox1");
// box = (CheckBox)orow.FindControl("checkBox1");
if (box.Checked==true )
{
int x = int.Parse(GridView1.DataKeys[orow.RowIndex ].Value.ToString());
//SqlDataSource1.DeleteParameters["id"].DefaultValue = x.ToString();
//SqlDataSource1.Delete();
cmd.CommandText = "del";
cmd.CommandType = CommandType.StoredProcedure;
p.ParameterName = "ids";
p.Value = x;
cmd.Parameters.Add(p);
//SqlDataSource1.DeleteParameters["@id"].DefaultValue = x.ToString();
//SqlDataSource1.Delete();
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
GridView1.DataBind();
SqlDataSource1.DataBind();
}
}
}</FONT></P> <P align=left><FONT size=3>
وتأتيني الرساله التالية عند حذف احد الصفوف
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
وتعلم على السطر التالي اي ان فيه الخلل
int x = int.Parse(GridView1.DataKeys[orow.RowIndex ].Value.ToString());