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

x
?
Solved

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

Posted on 2007-10-15
2
Medium Priority
?
604 Views
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">
            <Columns>
                  <common:EditButtonColumn ToolTipKey="" TextKey="" HeaderText="View"></common:EditButtonColumn>
                  <asp:TemplateColumn SortExpression="NM.ID_NUM" HeaderText="ID Number">
                        <ItemTemplate>
                              <%# DataBinder.Eval(Container.DataItem,"ID_NUM") %>
                        </ItemTemplate>
                  </asp:TemplateColumn>
                  <asp:TemplateColumn SortExpression="NM.FIRST_NAME" HeaderText="First Name">
                        <ItemTemplate>
                              <%# DataBinder.Eval(Container.DataItem,"FIRST_NAME") %>
                        </ItemTemplate>
                  </asp:TemplateColumn>
                  <asp:TemplateColumn SortExpression="NM.LAST_NAME" HeaderText="Last Name">
                        <ItemTemplate>
                              <%# DataBinder.Eval(Container.DataItem,"LAST_NAME") %>
                        </ItemTemplate>
                  </asp:TemplateColumn>
                  <asp:TemplateColumn HeaderText="DOB">
                        <ItemTemplate>
                              <%# DataBinder.Eval(Container.DataItem,"DOB") %>
                        </ItemTemplate>
                  </asp:TemplateColumn>
                  <asp:TemplateColumn SortExpression="BM.GENDER" HeaderText="Gender">
                        <ItemTemplate>
                              <%# DataBinder.Eval(Container.DataItem,"GENDER") %>
                        </ItemTemplate>
                  </asp:TemplateColumn>
            </Columns>
            <PagerStyle HorizontalAlign="Right" Mode="NumericPages"></PagerStyle>
      </common:groupedgrid>

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();
                  //Response.Write(grdSearchResults.DataKeys[e.Item.ItemIndex]);
                  
                  this.ParentPortlet.NextScreen("Student_Detail");

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

Thanks for any assistance!

Bill
0
Comment
Question by:blouckswwu
2 Comments
 
LVL 12

Accepted Solution

by:
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.
0
 

Author Comment

by:blouckswwu
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!

Bill
0

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