databind. Of course if you databind to an empty dataset your grid will be
page object. The datagrid should certainly re-populate itself from
viewstate. If it doesn't then something else is wrong with your code.
S. Justin Gengo, MCP
"Stamen Gortchev" <nospam@nospam.de> wrote in message
news:O%234eAYChDHA.1048@TK2MSFTNGP11.phx.gbl...
> 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=clickedIndex
> 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@aboutfortunate.com> schrieb im Newsbeitrag
> news:%23D14Ha6gDHA.1700@TK2MSFTNGP10.phx.gbl...
> > 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@onventis.de> wrote in message
> > news:ODSqq23gDHA.2124@TK2MSFTNGP12.phx.gbl...
> > > 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(object sender, System.EventArgs e)
> > > {
> > > if (!IsPostBack)
> > > {
> > > this.da.Fill(ds1, "Countrys");
> > > this.DataGrid1.DataBind();
> > > }
> > > }
> > >
> > > private void DataGrid1_EditCommand(object source,
> > > System.Web.UI.WebControls.DataGridCommandEventArgs e)
> > > {
> > > this.da.Fill(ds1, "Names");
> > > DataGrid1.EditItemIndex = e.Item.ItemIndex;
> > > DataGrid1.DataBind();
> > > }
> > >
> > > What do you think about it?
> > >
> > > Thanks
> > > Stamen
> > >
> > >
> > > "S. Justin Gengo" <sjgengo@aboutfortunate.com> schrieb im Newsbeitrag
> > > news:eNuFsp2gDHA.2292@TK2MSFTNGP10.phx.gbl...
> > > > 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@onventis.de> wrote in message
> > > > news:uuNuSR0gDHA.1648@TK2MSFTNGP10.phx.gbl...
> > > > > 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.DataBind()
> > > > > ========================
> > > > >
> > > > > 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