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. Advertising

  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. Advertising

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. Keshav Gadia
    Replies:
    2
    Views:
    626
    Keshav Gadia
    Sep 13, 2004
  2. Schultz
    Replies:
    3
    Views:
    555
    =?Utf-8?B?QmlsbCBCb3Jn?=
    Feb 14, 2005
  3. Replies:
    1
    Views:
    1,605
    S. Justin Gengo
    Nov 8, 2005
  4. Ilpo =?iso-8859-1?Q?Nyyss=F6nen?=

    XSL: Parametrized copies of a common block

    Ilpo =?iso-8859-1?Q?Nyyss=F6nen?=, May 24, 2004, in forum: XML
    Replies:
    1
    Views:
    356
    Ilpo =?iso-8859-1?Q?Nyyss=F6nen?=
    May 24, 2004
  5. D
    Replies:
    0
    Views:
    203
Loading...

Share This Page