Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

GridView.EditIndex always shows -1

Posted on 2012-03-14
2
Medium Priority
?
392 Views
Last Modified: 2012-03-14
Hello experts,
When I edit a row in my GridView, the EditIndex always shows -1 in my gvBonuses_RowDataBound event. Can anyone tell me why this is happening? Gridview code is below:

            <asp:GridView ID="gvBonuses" ValidationGroup="Edit" runat="server" AutoGenerateColumns="False" 
                DataKeyNames="id" DataSourceID="sdsBonuses" CssClass="mGrid" 
            OnRowDeleting="gvBonuses_RowDeleting" OnRowUpdated="gvBonuses_RowUpdated" 
            OnRowEditing="gvBonuses_RowEditing" OnRowDeleted="gvBonuses_RowDeleted" 
            OnRowUpdating="gvBonuses_RowUpdating" OnRowDataBound="gvBonuses_RowDataBound"
            >
                <Columns>
                    <asp:CommandField ShowEditButton="True" ValidationGroup="Edit" CausesValidation="true"/>
                    <asp:BoundField DataField="id" ReadOnly="True" Visible="false" />
                    <asp:BoundField DataField="employee_id" HeaderText="Employee ID" ReadOnly="True" 
                        SortExpression="employee_id" Visible="false"/>
                    <asp:BoundField DataField="name" HeaderText="Payee Name" ReadOnly="True" 
                        SortExpression="name" />
                    <asp:BoundField DataField="pay_code_desc" HeaderText="Pay Code" ReadOnly="True" 
                        SortExpression="pay_code_desc" />
                    <asp:BoundField DataField="gl_account" HeaderText="GL Account" ReadOnly="True" 
                        SortExpression="gl_account" />

                    <asp:TemplateField HeaderText="Loc #"> 
                    <ItemTemplate> <asp:Label ID="lblLocItem" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "location_num") %>'></asp:Label> </ItemTemplate>
                    <EditItemTemplate> <asp:DropDownList ID="ddlLocEdit" AppendDataBoundItems="true" runat="server" DataTextField="loc" DataValueField="loc" Text='<%# DataBinder.Eval(Container.DataItem, "location_num") %>'>
                    </asp:DropDownList> </EditItemTemplate>
                     </asp:TemplateField>  

                    <asp:TemplateField HeaderText="Amount"> 
                    <ItemTemplate> <asp:Label ID="lblAmount" runat="server" DataFormatString="{0:c}" Text='<%# DataBinder.Eval(Container.DataItem, "amount","{0:c}") %>'></asp:Label> </ItemTemplate>
                    <EditItemTemplate> <asp:TextBox ID="txtAmount" MaxLength="7" Width="75px" DataField="amount" DataFormatString="{0:N2}" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "amount","{0:N2}") %>'></asp:TextBox> 
                                 <asp:RangeValidator ID="rvGridAmount" ValidationGroup="Edit" runat="server" style="color:red;" ErrorMessage=" * Bonus Amount must be less than $10,000" ControlToValidate="txtAmount" MaximumValue="9999.99" MinimumValue=".01" Visible="True" Type="Currency" EnableClientScript="true" Display="Dynamic"></asp:RangeValidator>        
                                 <asp:RequiredFieldValidator ValidationGroup="Edit" style="color:red;" ID="rfvGridAmount" runat="server" ErrorMessage=" * You must enter a Bonus Amount" ControlToValidate="txtAmount" BackColor="White" Visible="True" EnableClientScript="true" Display="Dynamic"></asp:RequiredFieldValidator>       
                     </EditItemTemplate>
                     </asp:TemplateField> 

                    <asp:TemplateField HeaderText="Driving Category"> 
                    <ItemTemplate> <asp:Label ID="lblCategoryItem" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "category") %>'></asp:Label> </ItemTemplate>
                    <EditItemTemplate> <asp:DropDownList ID="ddlCategoryEdit"  runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "category") %>'>
                <asp:ListItem Text="Drive Overall Sales" Value="Drive Overall Sales" />
                <asp:ListItem Text="Drive Heritage Production" Value="Drive Heritage Production" />
                <asp:ListItem Text="Drive Atneed Merchandise" Value="Drive Atneed Merchandise" />
                <asp:ListItem Text="Drive PAF Production" Value="Drive PAF Production" />
                <asp:ListItem Text="Other" Value="Other" /> 
                    </asp:DropDownList> </EditItemTemplate>
                     </asp:TemplateField>  

                    <asp:TemplateField HeaderText="Explanation"> 
                    <ItemTemplate> <asp:Label ID="lblExplanation"  runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "explanation") %>'></asp:Label> </ItemTemplate>
                    <EditItemTemplate> <asp:TextBox ID="txtExplanation"  MaxLength="50" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "explanation") %>'></asp:TextBox> 
                                <asp:RequiredFieldValidator ValidationGroup="Edit" style="color:red;" ID="rfvGridExplanation" runat="server" ErrorMessage=" * You must enter an Explanation" ControlToValidate="txtExplanation" BackColor="White" Visible="True" EnableClientScript="true" Display="Dynamic"></asp:RequiredFieldValidator>       
                    </EditItemTemplate>
                     </asp:TemplateField>  

                    <asp:BoundField DataField="submitter_name" HeaderText="Requested By" ReadOnly="True" 
                        SortExpression="submitter_name" />
                    <asp:BoundField DataField="created_date" HeaderText="Request Date" ReadOnly="True" 
                        SortExpression="created_date" DataFormatString="{0:d}"/>
                    <asp:BoundField DataField="bonus_status" HeaderText="Status" ReadOnly="True" 
                        SortExpression="bonus_status" />

                    <asp:BoundField DataField="approved_denied_by" HeaderText="Approved/Denied By" ReadOnly="True" 
                        SortExpression="approved_denied_by" />
                    <asp:BoundField DataField="approved_denied_date" HeaderText="Approved/Denied Date" ReadOnly="True" 
                        SortExpression="approved_denied_date" DataFormatString="{0:d}"/>
                   
                    <asp:TemplateField HeaderText="Deny" ItemStyle-HorizontalAlign="Center" ItemStyle-VerticalAlign="Middle"> 
                    <ItemTemplate> 
                    <asp:ImageButton ID="ibtnDeny" runat="server" ImageUrl="..\..\images\delete.jpg" OnClick="ibtnDeny_Click" RowIndex='<%# DataBinder.Eval(Container.DataItem, "id") %>'  CommandName="deny" ImageAlign="AbsMiddle">
                    </asp:ImageButton>
                    </ItemTemplate>
                     </asp:TemplateField> 
                         
                    <asp:TemplateField HeaderText="Approve" ItemStyle-HorizontalAlign="Center" ItemStyle-VerticalAlign="Middle"> 
                    <ItemTemplate> 
                    <asp:ImageButton ID="ibtnApprove" runat="server" ImageUrl="..\..\images\green_drill.jpg" OnClick="ibtnApprove_Click" RowIndex='<%# DataBinder.Eval(Container.DataItem, "id") %>'  CommandName="approve" ImageAlign="AbsMiddle">
                    </asp:ImageButton>
                    </ItemTemplate>
                     </asp:TemplateField>                 

                </Columns>
            </asp:GridView>

Open in new window

0
Comment
Question by:dpicco
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 41

Accepted Solution

by:
Kyle Abrahams earned 2000 total points
ID: 37722411
how are you binding the data?


The most common cause of this is that you're binding this outside the

if (!Page.IsPostBack)
0
 
LVL 3

Author Closing Comment

by:dpicco
ID: 37722556
Yep that was the problem. Thanks  You're smart.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

609 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