Edit a row in a parametrized datagrid

B

berto

hi all,
I am working in ASP.NET & SQLServer and:
my problem is that I have a DataGrid wich is created sometimes with a
whole SQLServer table, and other times with only some rows of it (I
make a search in the same page).
The problem is that I have an edit column in the DataGrid, but if I
make a search and for example 2 rows are returned, if I click (for
example) on the second row to edit it, the DataGrid returns to the
listing of all the rows of the table and the row wich is editable is
not the one I clicked it's (in that case) the second row of the table.

Is there any way I can do that?

Here's the code I use to search and the one I use to bind the datagrid.
I hope someone can help me. Thanks in advance

CODE:
// sub for searching
Sub CercarClick(Source As Object, e As EventArgs)

Dim DS As DataSet
Dim MyDA As SqlDataAdapter
Dim MyCmd As SqlCommand

if name.value<>"" then
// name is the search field
MyDA = New SqlDataAdapter()
MyCmd = new SqlCommand("limp_CercaUsers", MyConnection)
MyCmd.Parameters.Add("@UserName", SqlDbType.VarChar, 10)
MyCmd.Parameters("@UserName").Value = name.value
MyCmd.CommandType = CommandType.StoredProcedure
MyDA.SelectCommand = MyCmd

DS = new DataSet()
MyDA.Fill(DS, "limp_usuarisLyser")

MyDataGrid.DataSource = DS.Tables("limp_usuarisLyser").DefaultView
MyDataGrid.DataBind()

else
Message.Text = "ERROR"
end if

End sub

// code I use to Bind the Data
Sub BindGrid()

Dim DS As DataSet
Dim MyCommand As SqlDataAdapter
MyCommand = new SqlDataAdapter("select * from limp_usuarisLyser",
MyConnection)

DS = new DataSet()
MyCommand.Fill(DS, "limp_usuarisLyser")

MyDataGrid.DataSource=DS.Tables("limp_usuarisLyser").DefaultView
MyDataGrid.DataBind()

End Sub
 
B

berto

well, I found a solution by myself:
I'll explain it because it colud help someone sometime: I just added a
hidden field in the form where I save the actual state searching/not
searching, so if the datagrid i had was the result of a search, the
DataGrid_Edit, _Cancel & _Update functions perform the same search
again instead of binding the whole sql table again.

I don't know if I explained myself well, but I hope so :p
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top