GridView RowEdit Index FindControl问题 [英] GridView RowEdit Index FindControl problem

查看:94
本文介绍了GridView RowEdit Index FindControl问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨团队

请帮助我.我在GridView RowEditing事件中找不到控件.这是我的代码.


Hi Team

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


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: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

推荐答案

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


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.


这篇关于GridView RowEdit Index FindControl问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆