[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


Datagrid Item.ItemIndex is pulling the next row instead of the correct row

Posted on 2007-10-15
Medium Priority
Last Modified: 2012-06-21
I am creating a custom web application for our online portal.  I am using C# to code this application and I am having a problem with my data grid.  I can get the data to display on the datagrid, but when I select the edit command the value (Student ID Number) is one off.  For example if I select the first item on the datagrid to edit and pulls the key information of the next one down on the datagrid.

Here is the datagrid code.  Please note that the groupedgrid is a custom function using the datagrid that was developed by our online portal product developer but uses the same properties:

      <common:groupedgrid id="grdSearchResults" RenderGroupHeaders="True" runat="server" GridLines="None"
            HeaderRightColumns="(Collection)" allowsorting="True" allowpaging="True" PagerStyle-Mode="NumericPages"
            PagerStyle-HorizontalAlign="Right" RenderTableFooters="True" ShowFooter="True" DataKeyField="ID_NUM">
                  <common:EditButtonColumn ToolTipKey="" TextKey="" HeaderText="View"></common:EditButtonColumn>
                  <asp:TemplateColumn SortExpression="NM.ID_NUM" HeaderText="ID Number">
                              <%# DataBinder.Eval(Container.DataItem,"ID_NUM") %>
                  <asp:TemplateColumn SortExpression="NM.FIRST_NAME" HeaderText="First Name">
                              <%# DataBinder.Eval(Container.DataItem,"FIRST_NAME") %>
                  <asp:TemplateColumn SortExpression="NM.LAST_NAME" HeaderText="Last Name">
                              <%# DataBinder.Eval(Container.DataItem,"LAST_NAME") %>
                  <asp:TemplateColumn HeaderText="DOB">
                              <%# DataBinder.Eval(Container.DataItem,"DOB") %>
                  <asp:TemplateColumn SortExpression="BM.GENDER" HeaderText="Gender">
                              <%# DataBinder.Eval(Container.DataItem,"GENDER") %>
            <PagerStyle HorizontalAlign="Right" Mode="NumericPages"></PagerStyle>

Here is the code behind for the edit function:

            private void grdSearchResults_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
                  this.ParentPortlet.PortletViewState["ID_NUM"] = grdSearchResults.DataKeys[e.Item.ItemIndex].ToString();
                  //Label1.Text = grdSearchResults.DataKeys[e.Item.ItemIndex].ToString();

I have used this method in the past and it has worked perfectly.

Thanks for any assistance!

Question by:blouckswwu
LVL 12

Accepted Solution

Ashley Bryant earned 1500 total points
ID: 20086241
Well, you could always just subtract 1 from grdSearchResults.DataKeys[e.Item.ItemIndex] if it's always only one off.  I know that's not really a solution, but it's a means to an end.

Author Comment

ID: 20086322
Actually I just rebuilt the datagrid and it works now.  I have ran into stuff like this before in VS 2003.  If all else fails...just redo it. :-)

I actually initially set it to subtract 1, but that makes me a little nervous because of potential inconsistencies (if it all of a sudden decided to work like it was designed).

I guess since you were the only one to respond I'll give you the points!

Have a good day and thanks for the response!


Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses
Course of the Month18 days, 20 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question