hi, the last days we need edit a row into gridview only with datasourse, so in many places any body has a entire solution to this, then, i decided post the code to solution this.

( note: in vfp this is easy, only a cursor, a grid and one append and replace or updatetable, easy.)

 

partial class _default

inherits system.web.ui.page

protected sub page_load(byval sender as object, byval e as system.eventargs) handles me.load

if not me.ispostback then

dim dv as new data.dataview

dim sql as new sqldatasource(configurationmanager.connectionstrings.item("democonnectionstring").tostring(), "select * from empleados")

dv = sql.select(ui.datasourceselectarguments.empty)

me.gridview1.datasource = dv

me.gridview1.databind()

end if

end sub

protected sub gridview1_rowupdating(byval sender as object, byval e as system.web.ui.webcontrols.gridviewupdateeventargs) handles gridview1.rowupdating

dim gv as gridview = directcast(sender, gridview)

for i as integer = 0 to gridview1.columns.count - 1

dim cell as datacontrolfieldcell = trycast(gv.rows(e.rowindex).cells(i), datacontrolfieldcell)

gv.columns(i).extractvaluesfromcell(e.newvalues, cell, datacontrolrowstate.edit, true)

next

end sub

protected sub gridview1_rowediting(byval sender as object, byval e as system.web.ui.webcontrols.gridviewediteventargs) handles gridview1.rowediting

dim gv as gridview = directcast(sender, gridview)

gv.editindex = e.neweditindex

gv.databind()

end sub

protected sub button1_click(byval sender as object, byval e as system.eventargs) handles button1.click

me.gridview1.editindex = 1

end sub

end class

 

 

best regards

 

franklin garzón

 

mvp visual foxpro

mcitp sqlserver

 

Leave a Reply

Your email address will not be published. Required fields are marked *