Click here to Skip to main content
15,893,161 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Team

Please help me in this. I could not able to find the Control in GridView RowEditing event. Here is my code.


C#
protected void gvNotes_RowEditing(object sender, GridViewEditEventArgs e)
    {
            if (gvNotes.EditIndex == -1)
            {
                gvNotes.EditIndex = e.NewEditIndex;
                DataTable dt = dc.BindNotesGrid(reportno);

                Label MyTextBox = (Label)gvNotes.Rows[e.NewEditIndex].Cells[1].FindControl("lblID");

        // MyTextBox is null while debugging        
        }
       
    }

ASP.NET
<asp:GridView ID="gvNotes" runat="server" AutoGenerateColumns="False" BackColor="White"
                        OnRowCommand="gvNotes_RowCommand" OnRowDeleting="gvNotes_RowDeleting"
                        OnRowEditing="gvNotes_RowEditing" OnRowCancelingEdit="gvNotes_RowCancelingEdit"
                        OnRowUpdating="gvNotes_RowUpdating" OnRowDataBound="gvNotes_RowDataBound" HeaderStyle-Height="35px"
                        CssClass="grid-view"
                        DataKeyNames="SevStatus1, id">


<asp:TemplateField HeaderStyle-Width="40px" HeaderText="Action" HeaderStyle-CssClass="headerbackcolor">
                                <ItemTemplate>
                                    <asp:ImageButton ID="ImageButton1" runat="server" CausesValidation="False" CommandName="Edit"
                                        ImageUrl="~/images/reply.png" Text="Edit" ToolTip="Edit" />
                                
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <asp:ImageButton ID="ImageButton1" runat="server" CausesValidation="True" OnClientClick="return gridcontrolsvalidate()"
                                        ValidationGroup="g1" CommandName="Update" ImageUrl="~/images/filesaveas.png"
                                        Text="Update" CommandArgument='<%#Eval("id") %>' ToolTip="Update" />
                                  
                                </EditItemTemplate>
                                
                            </asp:TemplateField>
 <asp:TemplateField HeaderText="ID" Visible="False">
                                <ItemTemplate>
                                    <asp:Label ID="Label8" runat="server" Text='<%# Bind("id") %>'></asp:Label>
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <asp:Label ID="lblID" runat="server" Text='<%# Bind("id") %>'></asp:Label>
                                </EditItemTemplate>
                                <ItemStyle HorizontalAlign="Center" />
                            </asp:TemplateField>


I'm not able to find the Control. please help me

Thanks
Posted
Updated 20-Sep-12 0:47am
v3

C#
Label MyTextBox = gvNotes.Rows[e.NewEditIndex].FindControl("lblID") as Label;
 
Share this answer
 
C#
protected void gvNotes_RowEditing(object sender, GridViewEditEventArgs e)
    {
        try
        {
            if (gvNotes.EditIndex == -1)
            {
                gvNotes.EditIndex = e.NewEditIndex;

                Label lblID = (Label)gvNotes.Rows[e.NewEditIndex].FindControl("lblID");
                BindNotesGrid();

            }
            // this.EnableViewState = true;
        }
        catch (Exception ex)
        {
            //Page.ClientScript.RegisterStartupScript(base.GetType(), "My startupscript", cs.message("Problem loading page,please try again after sometime"));
            Page.ClientScript.RegisterStartupScript(base.GetType(), "My startupscript", cs.message(ex.Message.ToString()));
        }

}

Still same problem.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900