Editing databound GridView values without updating

M

mpao

I have a ASP .NET application with GridView control bound to a
SQLDataSource, which calls a stored procedure. However, some of the
data needs to be localized (translated, formatted) before it's shown to
the user. It's not feasible to do this within the stored procedure. My
understanding is that to edit the values in a databound GridView, I
must specify the UpdateCommand-property. But I don't want to update
anything back to the database!

I tried creating a disconnected DataSet, changing the values and then
binding the GridView to that, but noticed that the automatic paging and
sorting features stopped working. I'm really not interested in writing
paging and sorting handlers when the GridView control is supposed to
contain those features already.

What is the easiest way use the GridView control that allows me to just
modify the dataset before displaying it, without ever taking any
changes back to the server?

Toni
 
C

Cor Ligthert [MVP]

I tried creating a disconnected DataSet, changing the values and then
binding the GridView to that, but noticed that the automatic paging and
sorting features stopped working.

Probably you did something wrong by instance in your binding, because AFAIK
does this work with a webform DataGrid, if this already implemented in the
Beta Version GridView is something I don't know.

Cor
 
M

mpao

Probably you did something wrong by instance in your binding, because AFAIK
does this work with a webform DataGrid, if this already implemented in the
Beta Version GridView is something I don't know.

Well how many ways are there to bind to a DataSet? The code looks like
this:

---

Dataset = Data.GetDataset("ic_sp_SalesInvoiceSelector", _
SessionCache.DB_Data)
SI_GridView.DataSource = Dataset

....

Public Function GetDataset(ByVal strSelectStatement As String, _
ByVal ConnectionString As String) As DataSet

Dim Recordset As DataSet
Dim DataAdapter As SqlDataAdapter
Dim Database As SqlConnection

Try
Database = New SqlConnection(ConnectionString)
DataAdapter = New SqlDataAdapter(strSelectStatement, _
ConnectionString)
Recordset = New DataSet()

DataAdapter.Fill(Recordset)
Database.Close()

Catch ex As Exception
Recordset = Nothing

End Try

Return Recordset

End Function

---

The GridView displays OK, but attempting to sort produces the following
error:

Exception Details: System.Web.HttpException: The GridView 'SI_GridView'
fired event Sorting which wasn't handled.
 
C

Cor Ligthert [MVP]

Mpa,

I think that your first misunderstanding you can see in your code. A dataset
is not something the same as a recordset. A datatable can be seen as a kind
of recordset.

However that is not the problem.

You are acting with servercontrols, for which you have to save its data, for
when the page comes back to get back its data,

Something as this in a kind of pseudo.

private ds as new dataset
Page load
if not ispostback then
dim ds as new dataset
bla bla bla
da.fill(ds)
mysession.item("theDataset") = ds
mygrid.datasource = ds.tables(0)
mygrid.databind
else
ds = mysession.item("theDataset")
mygrid.datasource = ds.Tables(0)
end if
end sub

In the last sub before post back
mygrid.databind

By the way setting something to nothing in a webpage as you do is completly
withouth sense. Everything is automaticly set to nothing.

I hope this helps,

Cor
 
M

mpao

Yes yes, OK, it was just rough code. I have no problems with persisting
the dataset. It still chokes upon not finding the event handler for the
sorting and paging. Are you actually able to get it to work on Beta 2?
 
C

Cor Ligthert [MVP]

Are you actually able to get it to work on Beta 2?See my first answer to you?

Cor
 

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

Top