MSDN Examples flawed

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Stamen Gortchev

    #1

    MSDN Examples flawed

    Hi all,

    I think there is an inherent problem with most examples on the internet
    (with MSDN, too!) showing datagrid's databinding. Here is, how they look
    like:

    =============== =========
    On Page_Load
    if !IsPostBack: BindGrid()

    On_Edit
    Set datagrid's EditItem to clicked item
    BindGrid

    void BindGrid()
    Fill DataSet through dataadapter
    DataGrid.DataBi nd()
    =============== =========

    Imagine a simple table "Names" with two columns: NameID and Name

    Your SQL Select Statement reads "SELECT NameID, Name FROM Names ORDER BY
    Name" and you have two records in it:
    ID=1, Name = "aaaa"
    ID=2, Name = "cccc"

    So, the first time you call the page, you get following grid:
    1 "aaaa" edit-button
    2 "cccc" edit-button

    during the time in which you are viewing this html page on your IE someone
    inserts another record in the table: "ID=3, Name='bbbb'".
    Then you click the edit button of the second row into your grid (2
    "cccc") intending to edit the name "cccc". When you klick the edit button,
    however, you get following grid:
    1 "aaaa" edit-button
    3 [bbbb] - updatable!!! Update-button, cancel-button
    2 "cccc" edit-button

    I am sure, you ghet what the reason is. What is the best solution to guard
    against this problem?

    Thank you for taking your time and understanding what I mean. I thought of a
    logical solution which however does not work. In case a discussion occur, I
    will write about it.

    All best

    Stamen


  • S. Justin Gengo

    #2
    Re: MSDN Examples flawed

    Stamen,

    Typically when doing an operation like this you wouldn't rebind the grid
    before the edit operation.

    So, in the page load sub use:

    If Not IsPostBack Then
    '---Bind your grid here
    End If

    (Make certain that viewstate is turned on for the grid. This way you don't
    have to rebind the grid.)

    Then rebind the grid after you edit the data.

    Sincerely,

    --
    S. Justin Gengo, MCP
    Web Developer

    Free code library at:
    www.aboutfortunate.com

    "Out of chaos comes order."
    Nietzche


    "Stamen Gortchev" <s.gortchev@onv entis.de> wrote in message
    news:uuNuSR0gDH A.1648@TK2MSFTN GP10.phx.gbl...[color=blue]
    > Hi all,
    >
    > I think there is an inherent problem with most examples on the internet
    > (with MSDN, too!) showing datagrid's databinding. Here is, how they look
    > like:
    >
    > =============== =========
    > On Page_Load
    > if !IsPostBack: BindGrid()
    >
    > On_Edit
    > Set datagrid's EditItem to clicked item
    > BindGrid
    >
    > void BindGrid()
    > Fill DataSet through dataadapter
    > DataGrid.DataBi nd()
    > =============== =========
    >
    > Imagine a simple table "Names" with two columns: NameID and Name
    >
    > Your SQL Select Statement reads "SELECT NameID, Name FROM Names ORDER BY
    > Name" and you have two records in it:
    > ID=1, Name = "aaaa"
    > ID=2, Name = "cccc"
    >
    > So, the first time you call the page, you get following grid:
    > 1 "aaaa" edit-button
    > 2 "cccc" edit-button
    >
    > during the time in which you are viewing this html page on your IE someone
    > inserts another record in the table: "ID=3, Name='bbbb'".
    > Then you click the edit button of the second row into your grid (2
    > "cccc") intending to edit the name "cccc". When you klick the edit button,
    > however, you get following grid:
    > 1 "aaaa" edit-button
    > 3 [bbbb] - updatable!!! Update-button, cancel-button
    > 2 "cccc" edit-button
    >
    > I am sure, you ghet what the reason is. What is the best solution to guard
    > against this problem?
    >
    > Thank you for taking your time and understanding what I mean. I thought of[/color]
    a[color=blue]
    > logical solution which however does not work. In case a discussion occur,[/color]
    I[color=blue]
    > will write about it.
    >
    > All best
    >
    > Stamen
    >
    >[/color]


    Comment

    • Stamen Gortchev

      #3
      Re: MSDN Examples flawed

      Hallo Justin,

      thanks for replying. What you propose however is exactly what I am doing:
      The code below is not immune against database changes:

      private void Page_Load(objec t sender, System.EventArg s e)
      {
      if (!IsPostBack)
      {
      this.da.Fill(ds 1, "Countrys") ;
      this.DataGrid1. DataBind();
      }
      }

      private void DataGrid1_EditC ommand(object source,
      System.Web.UI.W ebControls.Data GridCommandEven tArgs e)
      {
      this.da.Fill(ds 1, "Names");
      DataGrid1.EditI temIndex = e.Item.ItemInde x;
      DataGrid1.DataB ind();
      }

      What do you think about it?

      Thanks
      Stamen


      "S. Justin Gengo" <sjgengo@aboutf ortunate.com> schrieb im Newsbeitrag
      news:eNuFsp2gDH A.2292@TK2MSFTN GP10.phx.gbl...[color=blue]
      > Stamen,
      >
      > Typically when doing an operation like this you wouldn't rebind the grid
      > before the edit operation.
      >
      > So, in the page load sub use:
      >
      > If Not IsPostBack Then
      > '---Bind your grid here
      > End If
      >
      > (Make certain that viewstate is turned on for the grid. This way you don't
      > have to rebind the grid.)
      >
      > Then rebind the grid after you edit the data.
      >
      > Sincerely,
      >
      > --
      > S. Justin Gengo, MCP
      > Web Developer
      >
      > Free code library at:
      > www.aboutfortunate.com
      >
      > "Out of chaos comes order."
      > Nietzche
      >
      >
      > "Stamen Gortchev" <s.gortchev@onv entis.de> wrote in message
      > news:uuNuSR0gDH A.1648@TK2MSFTN GP10.phx.gbl...[color=green]
      > > Hi all,
      > >
      > > I think there is an inherent problem with most examples on the internet
      > > (with MSDN, too!) showing datagrid's databinding. Here is, how they look
      > > like:
      > >
      > > =============== =========
      > > On Page_Load
      > > if !IsPostBack: BindGrid()
      > >
      > > On_Edit
      > > Set datagrid's EditItem to clicked item
      > > BindGrid
      > >
      > > void BindGrid()
      > > Fill DataSet through dataadapter
      > > DataGrid.DataBi nd()
      > > =============== =========
      > >
      > > Imagine a simple table "Names" with two columns: NameID and Name
      > >
      > > Your SQL Select Statement reads "SELECT NameID, Name FROM Names ORDER BY
      > > Name" and you have two records in it:
      > > ID=1, Name = "aaaa"
      > > ID=2, Name = "cccc"
      > >
      > > So, the first time you call the page, you get following grid:
      > > 1 "aaaa" edit-button
      > > 2 "cccc" edit-button
      > >
      > > during the time in which you are viewing this html page on your IE[/color][/color]
      someone[color=blue][color=green]
      > > inserts another record in the table: "ID=3, Name='bbbb'".
      > > Then you click the edit button of the second row into your grid (2
      > > "cccc") intending to edit the name "cccc". When you klick the edit[/color][/color]
      button,[color=blue][color=green]
      > > however, you get following grid:
      > > 1 "aaaa" edit-button
      > > 3 [bbbb] - updatable!!! Update-button, cancel-button
      > > 2 "cccc" edit-button
      > >
      > > I am sure, you ghet what the reason is. What is the best solution to[/color][/color]
      guard[color=blue][color=green]
      > > against this problem?
      > >
      > > Thank you for taking your time and understanding what I mean. I thought[/color][/color]
      of[color=blue]
      > a[color=green]
      > > logical solution which however does not work. In case a discussion[/color][/color]
      occur,[color=blue]
      > I[color=green]
      > > will write about it.
      > >
      > > All best
      > >
      > > Stamen
      > >
      > >[/color]
      >
      >[/color]


      Comment

      • John Saunders

        #4
        Re: MSDN Examples flawed

        "Stamen Gortchev" <s.gortchev@onv entis.de> wrote in message
        news:uuNuSR0gDH A.1648@TK2MSFTN GP10.phx.gbl...[color=blue]
        > Hi all,
        >
        > I think there is an inherent problem with most examples on the internet
        > (with MSDN, too!) showing datagrid's databinding. Here is, how they look
        > like:[/color]

        Could you please post a reference to an MSDN article which says you should
        reload the data from the database before the edit?
        --
        John Saunders
        Internet Engineer
        john.saunders@s urfcontrol.com


        Comment

        • S. Justin Gengo

          #5
          Re: MSDN Examples flawed

          Stamen,

          As long as your entries have a primary key I don't see how they could be
          compromised. Of course any well designed database uses a primary key to make
          certain that a row is unique.

          Are the Id's that you are referring to not primary keys?

          Sincerely,

          --
          S. Justin Gengo, MCP
          Web Developer

          Free code library at:
          www.aboutfortunate.com

          "Out of chaos comes order."
          Nietzche


          "Stamen Gortchev" <s.gortchev@onv entis.de> wrote in message
          news:ODSqq23gDH A.2124@TK2MSFTN GP12.phx.gbl...[color=blue]
          > Hallo Justin,
          >
          > thanks for replying. What you propose however is exactly what I am doing:
          > The code below is not immune against database changes:
          >
          > private void Page_Load(objec t sender, System.EventArg s e)
          > {
          > if (!IsPostBack)
          > {
          > this.da.Fill(ds 1, "Countrys") ;
          > this.DataGrid1. DataBind();
          > }
          > }
          >
          > private void DataGrid1_EditC ommand(object source,
          > System.Web.UI.W ebControls.Data GridCommandEven tArgs e)
          > {
          > this.da.Fill(ds 1, "Names");
          > DataGrid1.EditI temIndex = e.Item.ItemInde x;
          > DataGrid1.DataB ind();
          > }
          >
          > What do you think about it?
          >
          > Thanks
          > Stamen
          >
          >
          > "S. Justin Gengo" <sjgengo@aboutf ortunate.com> schrieb im Newsbeitrag
          > news:eNuFsp2gDH A.2292@TK2MSFTN GP10.phx.gbl...[color=green]
          > > Stamen,
          > >
          > > Typically when doing an operation like this you wouldn't rebind the grid
          > > before the edit operation.
          > >
          > > So, in the page load sub use:
          > >
          > > If Not IsPostBack Then
          > > '---Bind your grid here
          > > End If
          > >
          > > (Make certain that viewstate is turned on for the grid. This way you[/color][/color]
          don't[color=blue][color=green]
          > > have to rebind the grid.)
          > >
          > > Then rebind the grid after you edit the data.
          > >
          > > Sincerely,
          > >
          > > --
          > > S. Justin Gengo, MCP
          > > Web Developer
          > >
          > > Free code library at:
          > > www.aboutfortunate.com
          > >
          > > "Out of chaos comes order."
          > > Nietzche
          > >
          > >
          > > "Stamen Gortchev" <s.gortchev@onv entis.de> wrote in message
          > > news:uuNuSR0gDH A.1648@TK2MSFTN GP10.phx.gbl...[color=darkred]
          > > > Hi all,
          > > >
          > > > I think there is an inherent problem with most examples on the[/color][/color][/color]
          internet[color=blue][color=green][color=darkred]
          > > > (with MSDN, too!) showing datagrid's databinding. Here is, how they[/color][/color][/color]
          look[color=blue][color=green][color=darkred]
          > > > like:
          > > >
          > > > =============== =========
          > > > On Page_Load
          > > > if !IsPostBack: BindGrid()
          > > >
          > > > On_Edit
          > > > Set datagrid's EditItem to clicked item
          > > > BindGrid
          > > >
          > > > void BindGrid()
          > > > Fill DataSet through dataadapter
          > > > DataGrid.DataBi nd()
          > > > =============== =========
          > > >
          > > > Imagine a simple table "Names" with two columns: NameID and Name
          > > >
          > > > Your SQL Select Statement reads "SELECT NameID, Name FROM Names ORDER[/color][/color][/color]
          BY[color=blue][color=green][color=darkred]
          > > > Name" and you have two records in it:
          > > > ID=1, Name = "aaaa"
          > > > ID=2, Name = "cccc"
          > > >
          > > > So, the first time you call the page, you get following grid:
          > > > 1 "aaaa" edit-button
          > > > 2 "cccc" edit-button
          > > >
          > > > during the time in which you are viewing this html page on your IE[/color][/color]
          > someone[color=green][color=darkred]
          > > > inserts another record in the table: "ID=3, Name='bbbb'".
          > > > Then you click the edit button of the second row into your grid (2
          > > > "cccc") intending to edit the name "cccc". When you klick the edit[/color][/color]
          > button,[color=green][color=darkred]
          > > > however, you get following grid:
          > > > 1 "aaaa" edit-button
          > > > 3 [bbbb] - updatable!!! Update-button, cancel-button
          > > > 2 "cccc" edit-button
          > > >
          > > > I am sure, you ghet what the reason is. What is the best solution to[/color][/color]
          > guard[color=green][color=darkred]
          > > > against this problem?
          > > >
          > > > Thank you for taking your time and understanding what I mean. I[/color][/color][/color]
          thought[color=blue]
          > of[color=green]
          > > a[color=darkred]
          > > > logical solution which however does not work. In case a discussion[/color][/color]
          > occur,[color=green]
          > > I[color=darkred]
          > > > will write about it.
          > > >
          > > > All best
          > > >
          > > > Stamen
          > > >
          > > >[/color]
          > >
          > >[/color]
          >
          >[/color]


          Comment

          • Stamen Gortchev

            #6
            Re: MSDN Examples flawed

            Justin,

            sorry for the late response - I only use newsgroups from work..

            I know what you mean and I have tried it. Unfortunately, I still have that
            "one-click-delay". All I do is this:
            I pul a dataadapter on my Webform, fill dataset and bind it to a datagrid
            (all done with my mouse). Then in the page_load event I call
            If not ispostback
            dataadapter.fil l (ds, tablename)
            datagrid.databi nd

            And the Edit-event is the way you tell me. And it is still not
            working..:-( I do not tamper with the viewstate of neither element as per
            default it is always set to true, isn't it? I use VS2003.

            If you think I foget something, can you please send me a small example where
            it works - I hope it would be interesting for you to try it for yourself and
            then ou can perhaps email it to me. I will write you an email in order not
            to get thousands of virus mails into my mailbox.

            Thanks again

            Stamen

            "S. Justin Gengo" <sjgengo@aboutf ortunate.com> schrieb im Newsbeitrag
            news:O8oDGEDhDH A.2544@TK2MSFTN GP12.phx.gbl...[color=blue]
            > Stamen,
            >
            > In the example I emailed to you I forgot to tell you to also remove the
            > databind. Of course if you databind to an empty dataset your grid will be
            > blank.
            >
            > You should be making certain that the datagrid itself has it's viewstate[/color]
            set[color=blue]
            > to true (as should any object it may be contained in such as a panel and[/color]
            the[color=blue]
            > page object.
            >
            > Then your code should simply set that row to be editable:
            >
            > private void DataGrid1_EditC ommand(object source,
            > System.Web.UI.W ebControls.Data GridCommandEven tArgs e)
            > {
            > DataGrid1.EditI temIndex = e.Item.ItemInde x;
            > }
            >
            > Since the datagrid is now not being repopulated from the database it will
            > only contain the original data and thus no problem...
            >
            > Sincerely,
            >
            > --
            > S. Justin Gengo, MCP
            > Web Developer
            >
            > Free code library at:
            > www.aboutfortunate.com
            >
            > "Out of chaos comes order."
            > Nietzche
            >
            >
            > "Stamen Gortchev" <s.gortchev@onv entis.de> wrote in message
            > news:ODSqq23gDH A.2124@TK2MSFTN GP12.phx.gbl...[color=green]
            > > Hallo Justin,
            > >
            > > thanks for replying. What you propose however is exactly what I am[/color][/color]
            doing:[color=blue][color=green]
            > > The code below is not immune against database changes:
            > >
            > > private void Page_Load(objec t sender, System.EventArg s e)
            > > {
            > > if (!IsPostBack)
            > > {
            > > this.da.Fill(ds 1, "Countrys") ;
            > > this.DataGrid1. DataBind();
            > > }
            > > }
            > >
            > > private void DataGrid1_EditC ommand(object source,
            > > System.Web.UI.W ebControls.Data GridCommandEven tArgs e)
            > > {
            > > this.da.Fill(ds 1, "Names");
            > > DataGrid1.EditI temIndex = e.Item.ItemInde x;
            > > DataGrid1.DataB ind();
            > > }
            > >
            > > What do you think about it?
            > >
            > > Thanks
            > > Stamen
            > >
            > >
            > > "S. Justin Gengo" <sjgengo@aboutf ortunate.com> schrieb im Newsbeitrag
            > > news:eNuFsp2gDH A.2292@TK2MSFTN GP10.phx.gbl...[color=darkred]
            > > > Stamen,
            > > >
            > > > Typically when doing an operation like this you wouldn't rebind the[/color][/color][/color]
            grid[color=blue][color=green][color=darkred]
            > > > before the edit operation.
            > > >
            > > > So, in the page load sub use:
            > > >
            > > > If Not IsPostBack Then
            > > > '---Bind your grid here
            > > > End If
            > > >
            > > > (Make certain that viewstate is turned on for the grid. This way you[/color][/color]
            > don't[color=green][color=darkred]
            > > > have to rebind the grid.)
            > > >
            > > > Then rebind the grid after you edit the data.
            > > >
            > > > Sincerely,
            > > >
            > > > --
            > > > S. Justin Gengo, MCP
            > > > Web Developer
            > > >
            > > > Free code library at:
            > > > www.aboutfortunate.com
            > > >
            > > > "Out of chaos comes order."
            > > > Nietzche
            > > >
            > > >
            > > > "Stamen Gortchev" <s.gortchev@onv entis.de> wrote in message
            > > > news:uuNuSR0gDH A.1648@TK2MSFTN GP10.phx.gbl...
            > > > > Hi all,
            > > > >
            > > > > I think there is an inherent problem with most examples on the[/color][/color]
            > internet[color=green][color=darkred]
            > > > > (with MSDN, too!) showing datagrid's databinding. Here is, how they[/color][/color]
            > look[color=green][color=darkred]
            > > > > like:
            > > > >
            > > > > =============== =========
            > > > > On Page_Load
            > > > > if !IsPostBack: BindGrid()
            > > > >
            > > > > On_Edit
            > > > > Set datagrid's EditItem to clicked item
            > > > > BindGrid
            > > > >
            > > > > void BindGrid()
            > > > > Fill DataSet through dataadapter
            > > > > DataGrid.DataBi nd()
            > > > > =============== =========
            > > > >
            > > > > Imagine a simple table "Names" with two columns: NameID and Name
            > > > >
            > > > > Your SQL Select Statement reads "SELECT NameID, Name FROM Names[/color][/color][/color]
            ORDER[color=blue]
            > BY[color=green][color=darkred]
            > > > > Name" and you have two records in it:
            > > > > ID=1, Name = "aaaa"
            > > > > ID=2, Name = "cccc"
            > > > >
            > > > > So, the first time you call the page, you get following grid:
            > > > > 1 "aaaa" edit-button
            > > > > 2 "cccc" edit-button
            > > > >
            > > > > during the time in which you are viewing this html page on your IE[/color]
            > > someone[color=darkred]
            > > > > inserts another record in the table: "ID=3, Name='bbbb'".
            > > > > Then you click the edit button of the second row into your grid (2
            > > > > "cccc") intending to edit the name "cccc". When you klick the edit[/color]
            > > button,[color=darkred]
            > > > > however, you get following grid:
            > > > > 1 "aaaa" edit-button
            > > > > 3 [bbbb] - updatable!!! Update-button, cancel-button
            > > > > 2 "cccc" edit-button
            > > > >
            > > > > I am sure, you ghet what the reason is. What is the best solution to[/color]
            > > guard[color=darkred]
            > > > > against this problem?
            > > > >
            > > > > Thank you for taking your time and understanding what I mean. I[/color][/color]
            > thought[color=green]
            > > of[color=darkred]
            > > > a
            > > > > logical solution which however does not work. In case a discussion[/color]
            > > occur,[color=darkred]
            > > > I
            > > > > will write about it.
            > > > >
            > > > > All best
            > > > >
            > > > > Stamen
            > > > >
            > > > >
            > > >
            > > >[/color]
            > >
            > >[/color]
            >
            >[/color]


            Comment

            • Stamen Gortchev

              #7
              Re: MSDN Examples flawed

              John,

              an example of Datagrid using can be found at:
              http://msdn.microsoft.com/library/en...asp?frame=true

              Forget the Update event, concentrate on the Edit -it illustrates the point
              nicely.

              What they do is the following:
              They get the row number (for example 2) which should be edited from the
              datagrid's viewstate and set this row in the datagrid to be edited (row 2).
              then they re-read the data and rebind the grid. If, however, the newly
              reloaded data contains another row on that place (2) we get the
              inconsistency.

              I tried Auto generate columns=true, primary keys and so on... nothing
              wirks..

              Thanks
              Stamen

              "John Saunders" <john.saunders@ surfcontrol.com > schrieb im Newsbeitrag
              news:u6aY564gDH A.696@TK2MSFTNG P09.phx.gbl...[color=blue]
              > "Stamen Gortchev" <s.gortchev@onv entis.de> wrote in message
              > news:uuNuSR0gDH A.1648@TK2MSFTN GP10.phx.gbl...[color=green]
              > > Hi all,
              > >
              > > I think there is an inherent problem with most examples on the internet
              > > (with MSDN, too!) showing datagrid's databinding. Here is, how they look
              > > like:[/color]
              >
              > Could you please post a reference to an MSDN article which says you should
              > reload the data from the database before the edit?
              > --
              > John Saunders
              > Internet Engineer
              > john.saunders@s urfcontrol.com
              >
              >[/color]


              Comment

              • Stamen Gortchev

                #8
                Re: MSDN Examples flawed

                Hi Justin,

                the table has two Columns: CountryID and Country - the sorting is done on
                Country not on CountryID, which of course is a primary key. The prblem of
                this approach is that it expects when refilling the datagrid that all
                records will come in the same order, what is quite an optimistic expectation
                in the general case.

                I tried your proposition of not refilling the dataadapter - it does not work
                at all, as now data gets shown on the repost.

                I had tried another approach:

                On_Edit_Event
                set editIndex=click edIndex
                Exit

                hoping that the grid gets reloaded from the ViewState. Unfortunately this
                does not work for some reason: The first time i click [Edit], nothing
                happens. The second time I click - the record enters edit-state wehich I
                have clicked the first time - so there is something like a "one click lag".
                Therefore i think that the event comes up too late - when the grid has
                already been initialized or somethink like that..:-(

                That's it! The most rigorous approach seems to be like this:

                In the edit_event, read the id of the data reord (CountryID). Refill the
                Grid. Find the row containing the data record with the found ID. Set this
                row in Edit mode. But it beats the purpose of ViewState and all..

                Sorry for the long message

                Cheers

                Stamen



                "S. Justin Gengo" <sjgengo@aboutf ortunate.com> schrieb im Newsbeitrag
                news:%23D14Ha6g DHA.1700@TK2MSF TNGP10.phx.gbl. ..[color=blue]
                > Stamen,
                >
                > As long as your entries have a primary key I don't see how they could be
                > compromised. Of course any well designed database uses a primary key to[/color]
                make[color=blue]
                > certain that a row is unique.
                >
                > Are the Id's that you are referring to not primary keys?
                >
                > Sincerely,
                >
                > --
                > S. Justin Gengo, MCP
                > Web Developer
                >
                > Free code library at:
                > www.aboutfortunate.com
                >
                > "Out of chaos comes order."
                > Nietzche
                >
                >
                > "Stamen Gortchev" <s.gortchev@onv entis.de> wrote in message
                > news:ODSqq23gDH A.2124@TK2MSFTN GP12.phx.gbl...[color=green]
                > > Hallo Justin,
                > >
                > > thanks for replying. What you propose however is exactly what I am[/color][/color]
                doing:[color=blue][color=green]
                > > The code below is not immune against database changes:
                > >
                > > private void Page_Load(objec t sender, System.EventArg s e)
                > > {
                > > if (!IsPostBack)
                > > {
                > > this.da.Fill(ds 1, "Countrys") ;
                > > this.DataGrid1. DataBind();
                > > }
                > > }
                > >
                > > private void DataGrid1_EditC ommand(object source,
                > > System.Web.UI.W ebControls.Data GridCommandEven tArgs e)
                > > {
                > > this.da.Fill(ds 1, "Names");
                > > DataGrid1.EditI temIndex = e.Item.ItemInde x;
                > > DataGrid1.DataB ind();
                > > }
                > >
                > > What do you think about it?
                > >
                > > Thanks
                > > Stamen
                > >
                > >
                > > "S. Justin Gengo" <sjgengo@aboutf ortunate.com> schrieb im Newsbeitrag
                > > news:eNuFsp2gDH A.2292@TK2MSFTN GP10.phx.gbl...[color=darkred]
                > > > Stamen,
                > > >
                > > > Typically when doing an operation like this you wouldn't rebind the[/color][/color][/color]
                grid[color=blue][color=green][color=darkred]
                > > > before the edit operation.
                > > >
                > > > So, in the page load sub use:
                > > >
                > > > If Not IsPostBack Then
                > > > '---Bind your grid here
                > > > End If
                > > >
                > > > (Make certain that viewstate is turned on for the grid. This way you[/color][/color]
                > don't[color=green][color=darkred]
                > > > have to rebind the grid.)
                > > >
                > > > Then rebind the grid after you edit the data.
                > > >
                > > > Sincerely,
                > > >
                > > > --
                > > > S. Justin Gengo, MCP
                > > > Web Developer
                > > >
                > > > Free code library at:
                > > > www.aboutfortunate.com
                > > >
                > > > "Out of chaos comes order."
                > > > Nietzche
                > > >
                > > >
                > > > "Stamen Gortchev" <s.gortchev@onv entis.de> wrote in message
                > > > news:uuNuSR0gDH A.1648@TK2MSFTN GP10.phx.gbl...
                > > > > Hi all,
                > > > >
                > > > > I think there is an inherent problem with most examples on the[/color][/color]
                > internet[color=green][color=darkred]
                > > > > (with MSDN, too!) showing datagrid's databinding. Here is, how they[/color][/color]
                > look[color=green][color=darkred]
                > > > > like:
                > > > >
                > > > > =============== =========
                > > > > On Page_Load
                > > > > if !IsPostBack: BindGrid()
                > > > >
                > > > > On_Edit
                > > > > Set datagrid's EditItem to clicked item
                > > > > BindGrid
                > > > >
                > > > > void BindGrid()
                > > > > Fill DataSet through dataadapter
                > > > > DataGrid.DataBi nd()
                > > > > =============== =========
                > > > >
                > > > > Imagine a simple table "Names" with two columns: NameID and Name
                > > > >
                > > > > Your SQL Select Statement reads "SELECT NameID, Name FROM Names[/color][/color][/color]
                ORDER[color=blue]
                > BY[color=green][color=darkred]
                > > > > Name" and you have two records in it:
                > > > > ID=1, Name = "aaaa"
                > > > > ID=2, Name = "cccc"
                > > > >
                > > > > So, the first time you call the page, you get following grid:
                > > > > 1 "aaaa" edit-button
                > > > > 2 "cccc" edit-button
                > > > >
                > > > > during the time in which you are viewing this html page on your IE[/color]
                > > someone[color=darkred]
                > > > > inserts another record in the table: "ID=3, Name='bbbb'".
                > > > > Then you click the edit button of the second row into your grid (2
                > > > > "cccc") intending to edit the name "cccc". When you klick the edit[/color]
                > > button,[color=darkred]
                > > > > however, you get following grid:
                > > > > 1 "aaaa" edit-button
                > > > > 3 [bbbb] - updatable!!! Update-button, cancel-button
                > > > > 2 "cccc" edit-button
                > > > >
                > > > > I am sure, you ghet what the reason is. What is the best solution to[/color]
                > > guard[color=darkred]
                > > > > against this problem?
                > > > >
                > > > > Thank you for taking your time and understanding what I mean. I[/color][/color]
                > thought[color=green]
                > > of[color=darkred]
                > > > a
                > > > > logical solution which however does not work. In case a discussion[/color]
                > > occur,[color=darkred]
                > > > I
                > > > > will write about it.
                > > > >
                > > > > All best
                > > > >
                > > > > Stamen
                > > > >
                > > > >
                > > >
                > > >[/color]
                > >
                > >[/color]
                >
                >[/color]


                Comment

                • S. Justin Gengo

                  #9
                  Re: MSDN Examples flawed

                  Stamen,

                  In the example I emailed to you I forgot to tell you to also remove the
                  databind. Of course if you databind to an empty dataset your grid will be
                  blank.

                  You should be making certain that the datagrid itself has it's viewstate set
                  to true (as should any object it may be contained in such as a panel and the
                  page object.

                  Then your code should simply set that row to be editable:

                  private void DataGrid1_EditC ommand(object source,
                  System.Web.UI.W ebControls.Data GridCommandEven tArgs e)
                  {
                  DataGrid1.EditI temIndex = e.Item.ItemInde x;
                  }

                  Since the datagrid is now not being repopulated from the database it will
                  only contain the original data and thus no problem...

                  Sincerely,

                  --
                  S. Justin Gengo, MCP
                  Web Developer

                  Free code library at:
                  www.aboutfortunate.com

                  "Out of chaos comes order."
                  Nietzche


                  "Stamen Gortchev" <s.gortchev@onv entis.de> wrote in message
                  news:ODSqq23gDH A.2124@TK2MSFTN GP12.phx.gbl...[color=blue]
                  > Hallo Justin,
                  >
                  > thanks for replying. What you propose however is exactly what I am doing:
                  > The code below is not immune against database changes:
                  >
                  > private void Page_Load(objec t sender, System.EventArg s e)
                  > {
                  > if (!IsPostBack)
                  > {
                  > this.da.Fill(ds 1, "Countrys") ;
                  > this.DataGrid1. DataBind();
                  > }
                  > }
                  >
                  > private void DataGrid1_EditC ommand(object source,
                  > System.Web.UI.W ebControls.Data GridCommandEven tArgs e)
                  > {
                  > this.da.Fill(ds 1, "Names");
                  > DataGrid1.EditI temIndex = e.Item.ItemInde x;
                  > DataGrid1.DataB ind();
                  > }
                  >
                  > What do you think about it?
                  >
                  > Thanks
                  > Stamen
                  >
                  >
                  > "S. Justin Gengo" <sjgengo@aboutf ortunate.com> schrieb im Newsbeitrag
                  > news:eNuFsp2gDH A.2292@TK2MSFTN GP10.phx.gbl...[color=green]
                  > > Stamen,
                  > >
                  > > Typically when doing an operation like this you wouldn't rebind the grid
                  > > before the edit operation.
                  > >
                  > > So, in the page load sub use:
                  > >
                  > > If Not IsPostBack Then
                  > > '---Bind your grid here
                  > > End If
                  > >
                  > > (Make certain that viewstate is turned on for the grid. This way you[/color][/color]
                  don't[color=blue][color=green]
                  > > have to rebind the grid.)
                  > >
                  > > Then rebind the grid after you edit the data.
                  > >
                  > > Sincerely,
                  > >
                  > > --
                  > > S. Justin Gengo, MCP
                  > > Web Developer
                  > >
                  > > Free code library at:
                  > > www.aboutfortunate.com
                  > >
                  > > "Out of chaos comes order."
                  > > Nietzche
                  > >
                  > >
                  > > "Stamen Gortchev" <s.gortchev@onv entis.de> wrote in message
                  > > news:uuNuSR0gDH A.1648@TK2MSFTN GP10.phx.gbl...[color=darkred]
                  > > > Hi all,
                  > > >
                  > > > I think there is an inherent problem with most examples on the[/color][/color][/color]
                  internet[color=blue][color=green][color=darkred]
                  > > > (with MSDN, too!) showing datagrid's databinding. Here is, how they[/color][/color][/color]
                  look[color=blue][color=green][color=darkred]
                  > > > like:
                  > > >
                  > > > =============== =========
                  > > > On Page_Load
                  > > > if !IsPostBack: BindGrid()
                  > > >
                  > > > On_Edit
                  > > > Set datagrid's EditItem to clicked item
                  > > > BindGrid
                  > > >
                  > > > void BindGrid()
                  > > > Fill DataSet through dataadapter
                  > > > DataGrid.DataBi nd()
                  > > > =============== =========
                  > > >
                  > > > Imagine a simple table "Names" with two columns: NameID and Name
                  > > >
                  > > > Your SQL Select Statement reads "SELECT NameID, Name FROM Names ORDER[/color][/color][/color]
                  BY[color=blue][color=green][color=darkred]
                  > > > Name" and you have two records in it:
                  > > > ID=1, Name = "aaaa"
                  > > > ID=2, Name = "cccc"
                  > > >
                  > > > So, the first time you call the page, you get following grid:
                  > > > 1 "aaaa" edit-button
                  > > > 2 "cccc" edit-button
                  > > >
                  > > > during the time in which you are viewing this html page on your IE[/color][/color]
                  > someone[color=green][color=darkred]
                  > > > inserts another record in the table: "ID=3, Name='bbbb'".
                  > > > Then you click the edit button of the second row into your grid (2
                  > > > "cccc") intending to edit the name "cccc". When you klick the edit[/color][/color]
                  > button,[color=green][color=darkred]
                  > > > however, you get following grid:
                  > > > 1 "aaaa" edit-button
                  > > > 3 [bbbb] - updatable!!! Update-button, cancel-button
                  > > > 2 "cccc" edit-button
                  > > >
                  > > > I am sure, you ghet what the reason is. What is the best solution to[/color][/color]
                  > guard[color=green][color=darkred]
                  > > > against this problem?
                  > > >
                  > > > Thank you for taking your time and understanding what I mean. I[/color][/color][/color]
                  thought[color=blue]
                  > of[color=green]
                  > > a[color=darkred]
                  > > > logical solution which however does not work. In case a discussion[/color][/color]
                  > occur,[color=green]
                  > > I[color=darkred]
                  > > > will write about it.
                  > > >
                  > > > All best
                  > > >
                  > > > Stamen
                  > > >
                  > > >[/color]
                  > >
                  > >[/color]
                  >
                  >[/color]


                  Comment

                  • S. Justin Gengo

                    #10
                    Re: MSDN Examples flawed

                    Stamen,

                    In the example I emailed to you I forgot to tell you to also remove the
                    databind. Of course if you databind to an empty dataset your grid will be
                    blank.

                    You should be making certain that the datagrid itself has it's viewstate set
                    to true (as should any object it may be contained in such as a panel and the
                    page object. The datagrid should certainly re-populate itself from
                    viewstate. If it doesn't then something else is wrong with your code.

                    Then your code should simply set that row to be editable:

                    private void DataGrid1_EditC ommand(object source,
                    System.Web.UI.W ebControls.Data GridCommandEven tArgs e)
                    {
                    DataGrid1.EditI temIndex = e.Item.ItemInde x;
                    }

                    Since the datagrid is now not being repopulated from the database it will
                    only contain the original data and thus no problem...

                    Sincerely,

                    --
                    S. Justin Gengo, MCP
                    Web Developer

                    Free code library at:
                    www.aboutfortunate.com

                    "Out of chaos comes order."
                    Nietzche


                    "Stamen Gortchev" <nospam@nospam. de> wrote in message
                    news:O%234eAYCh DHA.1048@TK2MSF TNGP11.phx.gbl. ..[color=blue]
                    > Hi Justin,
                    >
                    > the table has two Columns: CountryID and Country - the sorting is done on
                    > Country not on CountryID, which of course is a primary key. The prblem of
                    > this approach is that it expects when refilling the datagrid that all
                    > records will come in the same order, what is quite an optimistic[/color]
                    expectation[color=blue]
                    > in the general case.
                    >
                    > I tried your proposition of not refilling the dataadapter - it does not[/color]
                    work[color=blue]
                    > at all, as now data gets shown on the repost.
                    >
                    > I had tried another approach:
                    >
                    > On_Edit_Event
                    > set editIndex=click edIndex
                    > Exit
                    >
                    > hoping that the grid gets reloaded from the ViewState. Unfortunately this
                    > does not work for some reason: The first time i click [Edit], nothing
                    > happens. The second time I click - the record enters edit-state wehich I
                    > have clicked the first time - so there is something like a "one click[/color]
                    lag".[color=blue]
                    > Therefore i think that the event comes up too late - when the grid has
                    > already been initialized or somethink like that..:-(
                    >
                    > That's it! The most rigorous approach seems to be like this:
                    >
                    > In the edit_event, read the id of the data reord (CountryID). Refill the
                    > Grid. Find the row containing the data record with the found ID. Set this
                    > row in Edit mode. But it beats the purpose of ViewState and all..
                    >
                    > Sorry for the long message
                    >
                    > Cheers
                    >
                    > Stamen
                    >
                    >
                    >
                    > "S. Justin Gengo" <sjgengo@aboutf ortunate.com> schrieb im Newsbeitrag
                    > news:%23D14Ha6g DHA.1700@TK2MSF TNGP10.phx.gbl. ..[color=green]
                    > > Stamen,
                    > >
                    > > As long as your entries have a primary key I don't see how they could be
                    > > compromised. Of course any well designed database uses a primary key to[/color]
                    > make[color=green]
                    > > certain that a row is unique.
                    > >
                    > > Are the Id's that you are referring to not primary keys?
                    > >
                    > > Sincerely,
                    > >
                    > > --
                    > > S. Justin Gengo, MCP
                    > > Web Developer
                    > >
                    > > Free code library at:
                    > > www.aboutfortunate.com
                    > >
                    > > "Out of chaos comes order."
                    > > Nietzche
                    > >
                    > >
                    > > "Stamen Gortchev" <s.gortchev@onv entis.de> wrote in message
                    > > news:ODSqq23gDH A.2124@TK2MSFTN GP12.phx.gbl...[color=darkred]
                    > > > Hallo Justin,
                    > > >
                    > > > thanks for replying. What you propose however is exactly what I am[/color][/color]
                    > doing:[color=green][color=darkred]
                    > > > The code below is not immune against database changes:
                    > > >
                    > > > private void Page_Load(objec t sender, System.EventArg s e)
                    > > > {
                    > > > if (!IsPostBack)
                    > > > {
                    > > > this.da.Fill(ds 1, "Countrys") ;
                    > > > this.DataGrid1. DataBind();
                    > > > }
                    > > > }
                    > > >
                    > > > private void DataGrid1_EditC ommand(object source,
                    > > > System.Web.UI.W ebControls.Data GridCommandEven tArgs e)
                    > > > {
                    > > > this.da.Fill(ds 1, "Names");
                    > > > DataGrid1.EditI temIndex = e.Item.ItemInde x;
                    > > > DataGrid1.DataB ind();
                    > > > }
                    > > >
                    > > > What do you think about it?
                    > > >
                    > > > Thanks
                    > > > Stamen
                    > > >
                    > > >
                    > > > "S. Justin Gengo" <sjgengo@aboutf ortunate.com> schrieb im Newsbeitrag
                    > > > news:eNuFsp2gDH A.2292@TK2MSFTN GP10.phx.gbl...
                    > > > > Stamen,
                    > > > >
                    > > > > Typically when doing an operation like this you wouldn't rebind the[/color][/color]
                    > grid[color=green][color=darkred]
                    > > > > before the edit operation.
                    > > > >
                    > > > > So, in the page load sub use:
                    > > > >
                    > > > > If Not IsPostBack Then
                    > > > > '---Bind your grid here
                    > > > > End If
                    > > > >
                    > > > > (Make certain that viewstate is turned on for the grid. This way you[/color]
                    > > don't[color=darkred]
                    > > > > have to rebind the grid.)
                    > > > >
                    > > > > Then rebind the grid after you edit the data.
                    > > > >
                    > > > > Sincerely,
                    > > > >
                    > > > > --
                    > > > > S. Justin Gengo, MCP
                    > > > > Web Developer
                    > > > >
                    > > > > Free code library at:
                    > > > > www.aboutfortunate.com
                    > > > >
                    > > > > "Out of chaos comes order."
                    > > > > Nietzche
                    > > > >
                    > > > >
                    > > > > "Stamen Gortchev" <s.gortchev@onv entis.de> wrote in message
                    > > > > news:uuNuSR0gDH A.1648@TK2MSFTN GP10.phx.gbl...
                    > > > > > Hi all,
                    > > > > >
                    > > > > > I think there is an inherent problem with most examples on the[/color]
                    > > internet[color=darkred]
                    > > > > > (with MSDN, too!) showing datagrid's databinding. Here is, how[/color][/color][/color]
                    they[color=blue][color=green]
                    > > look[color=darkred]
                    > > > > > like:
                    > > > > >
                    > > > > > =============== =========
                    > > > > > On Page_Load
                    > > > > > if !IsPostBack: BindGrid()
                    > > > > >
                    > > > > > On_Edit
                    > > > > > Set datagrid's EditItem to clicked item
                    > > > > > BindGrid
                    > > > > >
                    > > > > > void BindGrid()
                    > > > > > Fill DataSet through dataadapter
                    > > > > > DataGrid.DataBi nd()
                    > > > > > =============== =========
                    > > > > >
                    > > > > > Imagine a simple table "Names" with two columns: NameID and Name
                    > > > > >
                    > > > > > Your SQL Select Statement reads "SELECT NameID, Name FROM Names[/color][/color]
                    > ORDER[color=green]
                    > > BY[color=darkred]
                    > > > > > Name" and you have two records in it:
                    > > > > > ID=1, Name = "aaaa"
                    > > > > > ID=2, Name = "cccc"
                    > > > > >
                    > > > > > So, the first time you call the page, you get following grid:
                    > > > > > 1 "aaaa" edit-button
                    > > > > > 2 "cccc" edit-button
                    > > > > >
                    > > > > > during the time in which you are viewing this html page on your IE
                    > > > someone
                    > > > > > inserts another record in the table: "ID=3, Name='bbbb'".
                    > > > > > Then you click the edit button of the second row into your grid (2
                    > > > > > "cccc") intending to edit the name "cccc". When you klick the edit
                    > > > button,
                    > > > > > however, you get following grid:
                    > > > > > 1 "aaaa" edit-button
                    > > > > > 3 [bbbb] - updatable!!! Update-button, cancel-button
                    > > > > > 2 "cccc" edit-button
                    > > > > >
                    > > > > > I am sure, you ghet what the reason is. What is the best solution[/color][/color][/color]
                    to[color=blue][color=green][color=darkred]
                    > > > guard
                    > > > > > against this problem?
                    > > > > >
                    > > > > > Thank you for taking your time and understanding what I mean. I[/color]
                    > > thought[color=darkred]
                    > > > of
                    > > > > a
                    > > > > > logical solution which however does not work. In case a discussion
                    > > > occur,
                    > > > > I
                    > > > > > will write about it.
                    > > > > >
                    > > > > > All best
                    > > > > >
                    > > > > > Stamen
                    > > > > >
                    > > > > >
                    > > > >
                    > > > >
                    > > >
                    > > >[/color]
                    > >
                    > >[/color]
                    >
                    >[/color]


                    Comment

                    • John Saunders

                      #11
                      Re: MSDN Examples flawed

                      "Stamen Gortchev" <nospam@nospam. de> wrote in message
                      news:O%234eAYCh DHA.1048@TK2MSF TNGP11.phx.gbl. ..[color=blue]
                      > Hi Justin,
                      >
                      > the table has two Columns: CountryID and Country - the sorting is done on
                      > Country not on CountryID, which of course is a primary key. The prblem of
                      > this approach is that it expects when refilling the datagrid that all
                      > records will come in the same order, what is quite an optimistic[/color]
                      expectation[color=blue]
                      > in the general case.
                      >
                      > I tried your proposition of not refilling the dataadapter - it does not[/color]
                      work[color=blue]
                      > at all, as now data gets shown on the repost.
                      >
                      > I had tried another approach:
                      >
                      > On_Edit_Event
                      > set editIndex=click edIndex
                      > Exit[/color]

                      Try calling DataGrid.DataBi nd after you set EditItemIndex.
                      --
                      John Saunders
                      Internet Engineer
                      john.saunders@s urfcontrol.com


                      Comment

                      • John Saunders

                        #12
                        Re: MSDN Examples flawed

                        "Stamen Gortchev" <nospam@nospam. de> wrote in message
                        news:OLSemXAhDH A.2544@TK2MSFTN GP12.phx.gbl...[color=blue]
                        > John,
                        >
                        > an example of Datagrid using can be found at:
                        >[/color]
                        http://msdn.microsoft.com/library/en...asp?frame=true

                        Stamen,

                        I took a look at that link, you're correct - that's a bug.

                        I submitted the issue to Microsoft by clicking the "feedback" link at the
                        bottom of the page. I got a response saying they'll look into correcting it
                        in future documentation. I was also told that the same pattern is used in
                        several places in the documentation and in the QuickStarts, and that the
                        issue will be raised for both.

                        I've had good response from the Microsoft Documentation and Training people
                        when I've commented on the MSDN documentation. I've always received a
                        prompt, courteous and even intelligent response. I haven't seen the results
                        in the documentation yet, but I'll be checking when the 2.0 documentation
                        comes out. : -)
                        --
                        John Saunders
                        Internet Engineer
                        john.saunders@s urfcontrol.com


                        Comment

                        • Stamen Gortchev

                          #13
                          Re: MSDN Examples flawed

                          Justin,

                          sorry for the late response - I only use newsgroups from work..

                          I know what you mean and I have tried it. Unfortunately, I still have that
                          "one-click-delay". All I do is this:
                          I pul a dataadapter on my Webform, fill dataset and bind it to a datagrid
                          (all done with my mouse). Then in the page_load event I call
                          If not ispostback
                          dataadapter.fil l (ds, tablename)
                          datagrid.databi nd

                          And the Edit-event is the way you tell me. And it is still not
                          working..:-( I do not tamper with the viewstate of neither element as per
                          default it is always set to true, isn't it? I use VS2003.

                          If you think I foget something, can you please send me a small example where
                          it works - I hope it would be interesting for you to try it for yourself and
                          then ou can perhaps email it to me. I will write you an email in order not
                          to get thousands of virus mails into my mailbox.

                          Thanks again

                          Stamen

                          "S. Justin Gengo" <sjgengo@aboutf ortunate.com> schrieb im Newsbeitrag
                          news:O8oDGEDhDH A.2544@TK2MSFTN GP12.phx.gbl...[color=blue]
                          > Stamen,
                          >
                          > In the example I emailed to you I forgot to tell you to also remove the
                          > databind. Of course if you databind to an empty dataset your grid will be
                          > blank.
                          >
                          > You should be making certain that the datagrid itself has it's viewstate[/color]
                          set[color=blue]
                          > to true (as should any object it may be contained in such as a panel and[/color]
                          the[color=blue]
                          > page object.
                          >
                          > Then your code should simply set that row to be editable:
                          >
                          > private void DataGrid1_EditC ommand(object source,
                          > System.Web.UI.W ebControls.Data GridCommandEven tArgs e)
                          > {
                          > DataGrid1.EditI temIndex = e.Item.ItemInde x;
                          > }
                          >
                          > Since the datagrid is now not being repopulated from the database it will
                          > only contain the original data and thus no problem...
                          >
                          > Sincerely,
                          >
                          > --
                          > S. Justin Gengo, MCP
                          > Web Developer
                          >
                          > Free code library at:
                          > www.aboutfortunate.com
                          >
                          > "Out of chaos comes order."
                          > Nietzche
                          >
                          >
                          > "Stamen Gortchev" <s.gortchev@onv entis.de> wrote in message
                          > news:ODSqq23gDH A.2124@TK2MSFTN GP12.phx.gbl...[color=green]
                          > > Hallo Justin,
                          > >
                          > > thanks for replying. What you propose however is exactly what I am[/color][/color]
                          doing:[color=blue][color=green]
                          > > The code below is not immune against database changes:
                          > >
                          > > private void Page_Load(objec t sender, System.EventArg s e)
                          > > {
                          > > if (!IsPostBack)
                          > > {
                          > > this.da.Fill(ds 1, "Countrys") ;
                          > > this.DataGrid1. DataBind();
                          > > }
                          > > }
                          > >
                          > > private void DataGrid1_EditC ommand(object source,
                          > > System.Web.UI.W ebControls.Data GridCommandEven tArgs e)
                          > > {
                          > > this.da.Fill(ds 1, "Names");
                          > > DataGrid1.EditI temIndex = e.Item.ItemInde x;
                          > > DataGrid1.DataB ind();
                          > > }
                          > >
                          > > What do you think about it?
                          > >
                          > > Thanks
                          > > Stamen
                          > >
                          > >
                          > > "S. Justin Gengo" <sjgengo@aboutf ortunate.com> schrieb im Newsbeitrag
                          > > news:eNuFsp2gDH A.2292@TK2MSFTN GP10.phx.gbl...[color=darkred]
                          > > > Stamen,
                          > > >
                          > > > Typically when doing an operation like this you wouldn't rebind the[/color][/color][/color]
                          grid[color=blue][color=green][color=darkred]
                          > > > before the edit operation.
                          > > >
                          > > > So, in the page load sub use:
                          > > >
                          > > > If Not IsPostBack Then
                          > > > '---Bind your grid here
                          > > > End If
                          > > >
                          > > > (Make certain that viewstate is turned on for the grid. This way you[/color][/color]
                          > don't[color=green][color=darkred]
                          > > > have to rebind the grid.)
                          > > >
                          > > > Then rebind the grid after you edit the data.
                          > > >
                          > > > Sincerely,
                          > > >
                          > > > --
                          > > > S. Justin Gengo, MCP
                          > > > Web Developer
                          > > >
                          > > > Free code library at:
                          > > > www.aboutfortunate.com
                          > > >
                          > > > "Out of chaos comes order."
                          > > > Nietzche
                          > > >
                          > > >
                          > > > "Stamen Gortchev" <s.gortchev@onv entis.de> wrote in message
                          > > > news:uuNuSR0gDH A.1648@TK2MSFTN GP10.phx.gbl...
                          > > > > Hi all,
                          > > > >
                          > > > > I think there is an inherent problem with most examples on the[/color][/color]
                          > internet[color=green][color=darkred]
                          > > > > (with MSDN, too!) showing datagrid's databinding. Here is, how they[/color][/color]
                          > look[color=green][color=darkred]
                          > > > > like:
                          > > > >
                          > > > > =============== =========
                          > > > > On Page_Load
                          > > > > if !IsPostBack: BindGrid()
                          > > > >
                          > > > > On_Edit
                          > > > > Set datagrid's EditItem to clicked item
                          > > > > BindGrid
                          > > > >
                          > > > > void BindGrid()
                          > > > > Fill DataSet through dataadapter
                          > > > > DataGrid.DataBi nd()
                          > > > > =============== =========
                          > > > >
                          > > > > Imagine a simple table "Names" with two columns: NameID and Name
                          > > > >
                          > > > > Your SQL Select Statement reads "SELECT NameID, Name FROM Names[/color][/color][/color]
                          ORDER[color=blue]
                          > BY[color=green][color=darkred]
                          > > > > Name" and you have two records in it:
                          > > > > ID=1, Name = "aaaa"
                          > > > > ID=2, Name = "cccc"
                          > > > >
                          > > > > So, the first time you call the page, you get following grid:
                          > > > > 1 "aaaa" edit-button
                          > > > > 2 "cccc" edit-button
                          > > > >
                          > > > > during the time in which you are viewing this html page on your IE[/color]
                          > > someone[color=darkred]
                          > > > > inserts another record in the table: "ID=3, Name='bbbb'".
                          > > > > Then you click the edit button of the second row into your grid (2
                          > > > > "cccc") intending to edit the name "cccc". When you klick the edit[/color]
                          > > button,[color=darkred]
                          > > > > however, you get following grid:
                          > > > > 1 "aaaa" edit-button
                          > > > > 3 [bbbb] - updatable!!! Update-button, cancel-button
                          > > > > 2 "cccc" edit-button
                          > > > >
                          > > > > I am sure, you ghet what the reason is. What is the best solution to[/color]
                          > > guard[color=darkred]
                          > > > > against this problem?
                          > > > >
                          > > > > Thank you for taking your time and understanding what I mean. I[/color][/color]
                          > thought[color=green]
                          > > of[color=darkred]
                          > > > a
                          > > > > logical solution which however does not work. In case a discussion[/color]
                          > > occur,[color=darkred]
                          > > > I
                          > > > > will write about it.
                          > > > >
                          > > > > All best
                          > > > >
                          > > > > Stamen
                          > > > >
                          > > > >
                          > > >
                          > > >[/color]
                          > >
                          > >[/color]
                          >
                          >[/color]


                          Comment

                          Working...