How can I close a DetailsView ?

R

Roberto Kohler

I would like to add a cancel command to a DetailsView so that when the
DetailsView is in ReadOnly Mode and a user clicks the Cancel button, the
DetailsView closes.

The DetailsView is linked to a GridView through an SQLDataSource that calls
a stored procedure using as parameters the SelectedDataKey.Values of the
GridView.

The GridView lists a bunch of records using the SQLDataSource "dsALLROWS"
that calls a stored procedure "sp_listAllRows"
The DetailsView shows one record using the SQLDataSource "dsONEROW" which is
linked to GridView through it's SelectControlParameters that point to the
selected record and it calls a stored procedure "sp_getOneRow @Param1,
@param2" with the SelectedDataKey.Values.

I tried closing the DetailsView by setting the GridView.selectedindex to -1,
but that did not work.
I tried setting the DetailsView1.DataSourceID to Nothing, but that did not
work either.

Any ideas?
 
R

Roberto Kohler

This worked:

Protected Sub DetailsView1_ItemCommand(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DetailsViewCommandEventArgs)
If e.CommandName.ToString = "Cancel" And
DetailsView1.CurrentMode.ToString = "ReadOnly" Then
GridView1.SelectedIndex = -1
End If

End Sub

Protected Sub btnCancel_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnCancelar.Click
' Close GridView
rsDEPTOS.CancelSelectOnNullParameter = True
rsDEPTOS.SelectParameters.Item("intOrden").DefaultValue =
String.Empty
rsDEPTOS.SelectParameters.Item("intDOrden").DefaultValue =
String.Empty
rsDEPTOS.SelectParameters.Item("strWHERE").DefaultValue =
String.Empty

' Close DetailsView
GridView1.SelectedIndex = -1

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top