Datagrid Editcommand for only record on second page not working


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 8 of 8

Thread: Datagrid Editcommand for only record on second page not working

  1. #1
    Join Date
    Aug 2005
    Posts
    79

    Exclamation Datagrid Editcommand for only record on second page not working

    Step 1: In my datagrid, if I click on the only row on the second page, it takes me to the first record on the first page.

    Step 2: If I add a second row to the second page, then click "Edit" on the top / first record on the second page, I can now edit that record that I couldn't edit in Step 1.

    Here's the Editcommand code:

    DataGrid1.EditItemIndex = e.Item.ItemIndex

    SqlDataAdapter1.Fill(Dssqla1, "Resource Table")
    SqlDataAdapter2.Fill(Dssqlb1, "Resource Table - Combo Codes")
    SqlDataAdapter3.Fill(Dssqlc1, "Signature_Authority_Names")

    DataGrid1.DataBind()

    Things I'm looking at are:
    1. The original datagrid on the EditCommand event simply populated dropdownlists in several of the fields in the datagrid. This worked fine, but the width allotment wasn't enough. These ddls were small and difficult for users to read.

    2. The new datagrid had the EditItem template changed and all three dropdownlists were placed in the same column to allow for the dropdownlists to have enough width and ample font size. It made the datagrid better from a UI perspective.

    I can't see anything different in the datagrid EditCommand in either version of the code. The ItemDataBound routine is the same too.

    I can look at the record in question (only record on second page) and paste the following data in a label of:

    lblItemIndex.Text = e.Item.ItemIndex.ToString() lblItemIndex &= " " & DataGrid1.CurrentPageIndex
    lblItemIndex.Text &= " " & e.Item.Cells(15).Text.toString()

    ...this label shows that I'm in fact clicking on that only record on the second page, but still the Datagrid goes to the first record on the first page. If I add another record, so now the second page has two records, I can then edit this particular record on the second page.

  2. #2
    Join Date
    May 2005
    Location
    UK
    Posts
    278
    The EditItem event is different from the selecteditem event , I think in STEP1 The later event is raised and I am not sure if you have code handling that event?
    Sri

  3. #3
    Join Date
    Aug 2005
    Posts
    79

    Question Not too sure what's happening....

    srinivas_s,

    Thanks for the response.

    The crazy thing is this page / datagrid is the same as before, but I've just changed the EditItem template. The previous page / datagrid works fine with the same code, the only difference is that I hide some unneeded columns with this new page, and place all the ddls in the same column to allow for more width and a larger font size.

    I can see the correct primary key, page index, and selected item in a label, so I know which one I clicked. I don't understand why adding another record to the second page causes everything to work correctly.

  4. #4
    Join Date
    May 2005
    Location
    UK
    Posts
    278
    What about the page reload, after the page loads again are you sure your page index is not -1, check using a break point in the event handler for selecteditem of the grid
    Sri

  5. #5
    Join Date
    Aug 2005
    Posts
    79
    What I did earlier to check was when the user would click the EditCommand, I had a label that would tell me the page index, item index, and Primary Key for the row. When the label came back, the EditCommand information in the label showed the correctly clicked row, but if there was only one row on the second page, I got the first item on the first page.

  6. #6
    Join Date
    Aug 2005
    Posts
    79
    Here's what I did for the EditCommand with one row on the second page, and I got 0 1

    lblDetails.Visible = True
    lblDetails.Text = e.Item.ItemIndex & " " & DataGrid1.CurrentPageIndex

    If I clicked on the first item on the first page, I got 0 0.

  7. #7
    Join Date
    May 2005
    Location
    UK
    Posts
    278
    Is viewstate enabled on the grid? Another thing can you add 10 more rows to extend the data to the third page, and have three pages, And if you still get the same problem it means the page index is reset on every page load, Try this and if the same problem comes up on the third page, use a variable in viewstate/ session for the page index to be maintained and then retrieve it when you bind and set it to the grids page index
    Sri

  8. #8
    Join Date
    May 2006
    Posts
    13

    Turn ASP.NET controls into AJAX-enabled controls

    Hi guys!

    I created a control that works like an AJAX container. Basically the way it works is that all the ASP.NET controls that you place inside of the AJAX container will automatically become AJAX enabled.

    For example, if you need to create a web form with three dropdownlists and you want the picked value of one DDL affects the items in the others DDLs (like in an auto dealer website) all you need to do is make sure you move these three dropdownlists into this AJAX container control. The way you code and setup the three dropdownlists remains exactly the same. The container control injects the necessary AJAX functions.

    I uploaded this control and posted some walkthrough tutorials at http://www.KYNOU.com

    Check it out!

Similar Threads

  1. DataGrid 'Record Selector'
    By Omar in forum VB Classic
    Replies: 1
    Last Post: 10-21-2001, 03:34 PM
  2. Replies: 1
    Last Post: 09-28-2001, 01:24 AM
  3. Replies: 0
    Last Post: 04-13-2001, 03:19 AM
  4. Replies: 0
    Last Post: 03-27-2001, 08:59 AM
  5. Datagrid control problem
    By Heath in forum VB Classic
    Replies: 1
    Last Post: 01-22-2001, 01:21 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center