Unusual looping in RowCommand

row command , gridview delete , asp.net gridview Toronto, Canada
  • 12 years ago
    hi, I have used following code for RowCommand event of a GridView: if (e.CommandName.ToLower().Trim() == "delete".ToLower()) { int RowNo = Convert.ToInt16(e.CommandArgument); if (DSet.Tables.Count > 0) { Code = DSet.Tables[0].Rows[RowNo]["pkLeaveCd"].ToString().Trim(); BLogic.DeleteRecord("tbLeaveMaster", "pkLeaveCd", Code); BindGridView(); } } When I debugged the code, i found that it loops twice through the code, first time it deletes the record..but when it loops for second time it gives the following error: Exception Details: System.IndexOutOfRangeException: There is no row at position 0. The above error is thrown in case if i trying to delete the last record....else it will give me the following error: Exception Details: System.Web.HttpException: The GridView 'grdVwLeaveType' fired event RowDeleting which wasn't handled. I am unable to undertand why it loops twice through the code...whereas the event is fired only once. any suggestions? Regards, Royal

Post a reply

No one has replied yet! Why not be the first?

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Any fool can write code that a computer can understand. Good programmers write code that humans can understand.” - Martin Fowler