.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> VB.Net >> Post New QuestionBookmark and Share Subscribe to Forum

update row when check with checkbox

Posted By: Catherine     Posted Date: May 18, 2011    Points:5   Category :VB.Net
hi i displayed details in gridview. when i select row using check box the selected row should be updated. here is my code. but error coming in this line chequenum = Convert.ToInt32(GridView1.DataKeys(row.RowIndex).Value) the error as Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index. please tell code in vb.net

Dim chequenum As Integer
For Each row As GridViewRow In GridView1.Rows
Dim chkbox As CheckBox = row.FindControl("chkbox")
'Dim chkbox As CheckBox = DirectCast(row.FindControl("chkbox"), CheckBox)
If chkbox.Checked = True Then

chequenum = Convert.ToInt32(GridView1.DataKeys(row.RowIndex).Value)

connection = New OleDbConnection(connectionString)
SQLstr = "Update stu_tbl set IsCancel='C' where stringid='" & chequenum & "'"


Dim cmd As New OleDbCommand(SQLstr, connection)

connection.Open()
cmd.ExecuteNonQuery()
MsgBox("Record Canceled")

connection.Close()

End If
Next
bindgrid()


Responses
Author: Mahesh             
Posted Date: May 19, 2011     Points: 20   

hi,
you should use actual value of the datakey which you are accessing as,

chequenum = Convert.ToInt32(GridView1.DataKeys(row.RowIndex).Values["EmpName"].ToString())

hope this helps..

Thanks
Mahesh



Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend