Edit a row in a parametrized datagrid

Discussion in 'ASP .Net Datagrid Control' started by berto, Jun 8, 2005.

  1. berto

    berto Guest

    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
     
    berto, Jun 8, 2005
    #1
    1. Advertisements

  2. berto

    berto Guest

    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
     
    berto, Jun 8, 2005
    #2
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. San Diego Guy
    Replies:
    0
    Views:
    722
    San Diego Guy
    Aug 7, 2003
  2. Mark Davidson
    Replies:
    0
    Views:
    496
    Mark Davidson
    Aug 11, 2003
  3. Dean J. Garrett

    Datagrid - edit row content

    Dean J. Garrett, Oct 15, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    438
    Dean J. Garrett
    Oct 15, 2003
  4. Schultz
    Replies:
    3
    Views:
    747
    =?Utf-8?B?QmlsbCBCb3Jn?=
    Feb 14, 2005
  5. Andreas Klemt
    Replies:
    0
    Views:
    491
    Andreas Klemt
    Oct 8, 2003
  6. Sharon McCarty
    Replies:
    0
    Views:
    403
    Sharon McCarty
    Nov 24, 2004
  7. Frank Kurka
    Replies:
    8
    Views:
    601
  8. D
    Replies:
    0
    Views:
    488
Loading...