TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Vineet Kumar Saini
NA
10.4k
7.4m
Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index
Dec 7 2012 12:29 AM
Hi Friends, Please help me
.cs page
========
protected void gridview1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["TestDBConnectionString"].ConnectionString.ToString());
int empid = Convert.ToInt32(gridview1.DataKeys[e.RowIndex].Values["emp_id"].ToString());
SqlCommand cmd = new SqlCommand("delete from emp where emp_id=" + empid + "", con);
con.Open();
int temp = cmd.ExecuteNonQuery();
con.Close();
}
.aspx page
========
<asp:GridView ID="gridview1" runat="server"
onrowcancelingedit="gridview1_RowCancelingEdit"
onrowdeleting="gridview1_RowDeleting" onrowediting="gridview1_RowEditing"
onrowupdating="gridview1_RowUpdating"
onselectedindexchanged="gridview1_SelectedIndexChanged">
<Columns>
<asp:CommandField ButtonType="Button" ShowDeleteButton="True"
ShowEditButton="True" />
</Columns>
</asp:GridView>
when we click on delete button then i get an erro i.e. "Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index". So Please tell me hoe to do remove this error ?
Thanks in advance !!
Reply
Answers (
9
)
how to handle Exception?
Comparing Two text Box values and Highlighting the Mismatch