0

我在更新面板中有一个gridview,它工作正常。但是,单击编辑按钮时,我想打开编辑表单。但是编辑按钮单击不起作用。当我调试它时,该方法工作正常,但是页面没有回发。我尝试过使用触发器,但无济于事。

    <asp:UpdatePanel ID="upnlgrid" runat="server" UpdateMode="Conditional" >
    <ContentTemplate>
    <asp:GridView ID="gvGroupMaster" runat="server" AutoGenerateColumns="False" OnSelectedIndexChanging="gvGroupMaster_SelectedIndexChanging" OnSelectedIndexChanged="gvGroupMaster_SelectedIndexChanged" OnRowDataBound="gvGroupMaster_RowDataBound"  AllowSorting="true" OnPageIndexChanging="gvGroupMaster_PageIndexChanging" OnSorting="gvGroupMaster_Sorting" 
ShowHeader="True" CssClass="tabledata" Width="100%" DataKeyNames="igroup_id">
                         <AlternatingRowStyle CssClass="pointer" />
<RowStyle CssClass="even pointer" />
<HeaderStyle CssClass="headings" />


                        <Columns>

                        <asp:TemplateField HeaderText="Sort Order" ItemStyle-CssClass="colmn1" SortExpression="isort_position" >
                           <ItemTemplate>
                          <%-- <asp:ImageButton ID="btnSort" OnClick="btnSortClick" imageurl="../images/order-sort-btnup.png" runat="server"></asp:ImageButton>--%>
           <asp:Button ID="btnSort" class="sortord pointer" runat="server" OnClick="btnSortClick" ></asp:Button>
           <asp:Button ID="btnSortDown" class="sortorddown pointer" runat="server" OnClick="btnSortDownClick"></asp:Button>


                             </ItemTemplate>
                            </asp:TemplateField>


                       <asp:TemplateField  HeaderText="Group Name" SortExpression="strgroup_name" ItemStyle-CssClass="colmn2" >

                            <ItemTemplate>
                            <asp:Label ID="lblGroupName" runat="server"
            Text='<%# Bind("strgroup_name") %>'></asp:Label>

                             </ItemTemplate>
                            </asp:TemplateField>



                             <asp:TemplateField HeaderText="Short Name" SortExpression="strgroup_sname" ItemStyle-CssClass="colmn3" >

                            <ItemTemplate>

                            <asp:Label ID="lblShortName" runat="server"
            Text='<%# Bind("strgroup_sname") %>'></asp:Label>


                            </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="Under" SortExpression="iparent_id" ItemStyle-CssClass="colmn4">

                            <ItemTemplate>
                             <asp:Label ID="lblUnder" runat="server"
            Text='<%# Bind("strunder") %>'></asp:Label>

                            </ItemTemplate>
                            </asp:TemplateField>


                             <asp:TemplateField HeaderText="Nature Of Group" SortExpression="strnature_of_group" ItemStyle-CssClass="colmn5">

                            <ItemTemplate>
                             <asp:Label ID="lblNatureOfGroup" runat="server"
            Text='<%# Bind("strnature_of_group") %>'></asp:Label>

                            </ItemTemplate>
                            </asp:TemplateField>


                             <asp:TemplateField HeaderText="Affect Gross Profit" SortExpression="straffect_gross_profits" ItemStyle-CssClass="colmn6">

                            <ItemTemplate>

                             <asp:Label ID="lblAffectGrossProfits" runat="server" Text='<%# Bind("straffect_gross_profits") %>'></asp:Label>

                            </ItemTemplate>
                            </asp:TemplateField>
                             <asp:TemplateField HeaderText="Nett DrCr Report" SortExpression="strnett_drcr_report"  ItemStyle-CssClass="colmn7">

                            <ItemTemplate>
                             <asp:Label ID="lblNettDrcrReport" runat="server"
            Text='<%# Bind("strnett_drcr_report") %>'></asp:Label>

                            </ItemTemplate>
                            </asp:TemplateField>


                            <asp:TemplateField HeaderText="Created By" SortExpression="icreated_by"  ItemStyle-CssClass="colmn8">

                            <ItemTemplate>
                             <asp:Label ID="lblCreatedBy" runat="server"
            Text='<%# Bind("strcreated_by") %>'></asp:Label>

                            </ItemTemplate>
                            </asp:TemplateField>


                             <asp:TemplateField HeaderText="Created On" SortExpression="dtcreated_on"  ItemStyle-CssClass="colmn9">

                            <ItemTemplate>
                             <asp:Label ID="lblCreatedOn" runat="server"
            Text='<%# Bind("dtcreated_on") %>'></asp:Label>

                            </ItemTemplate>
                            </asp:TemplateField>



                             <asp:TemplateField HeaderText="Last Updated On" SortExpression="dtupdated_on" ItemStyle-CssClass="colmn10">
                            <ItemTemplate>
                             <asp:Label ID="lbLastUpdatedOn" runat="server"
            Text='<%# Bind("dtupdated_on") %>'></asp:Label>

                            </ItemTemplate>
                            </asp:TemplateField>

                            <asp:TemplateField HeaderText="Actions" ItemStyle-CssClass="colmn11">

                             <ItemTemplate>
                             <asp:Button id="btnInfo" runat="server" class="infoicon" Text='<%# Eval("igroup_id") %>'  OnClick="infoclick"/>
                             &nbsp;&nbsp;
                             <asp:Button id="btnEdit" runat="server" class="editicon"  CausesValidation="false" Text='<%# Eval("igroup_id") %>'  OnClick="editclick"/>
                            &nbsp;&nbsp;
                             <asp:Button id="btnDelete" runat="server" class="deleteicon" Text='<%# Eval("igroup_id") %>' OnClick="deleteclick"/>
                             </ItemTemplate>
                             </asp:TemplateField>
                        </Columns>



                    </asp:GridView>
                   </ContentTemplate>

  </asp:UpdatePanel>

编辑点击的代码隐藏

 protected void editclick(object sender, EventArgs e)
{
    try
    {

       //int rindex = (((GridViewRow)(((Button)(sender)).Parent.BindingContainer))).RowIndex;
        Button EditButton = (Button)gvGroupMaster.Rows[(((GridViewRow)(((Button)(sender)).Parent.BindingContainer))).RowIndex].FindControl("btnEdit");
        edit(EditButton.Text.ToString());
        this.Session["edit"] = EditButton.Text.ToString();

    }
    catch
    {
    }
}

protected void edit(string editid)
{
    try
    {
        GroupMasterClass gm = new GroupMasterClass();
        CompanyMasterClass co = new CompanyMasterClass();
        gm.igroup_id = Convert.ToInt32(editid);
        ResultClass objres = gm.fn_GetGroupByIdForEdit();
        if (objres.bStatus)
        {
            eslist<GroupMasterClass> OBJLIST = objres.objData as eslist<GroupMasterClass>;
            if (OBJLIST.Count > 0)
            {
                co.strcompany_code = Request.Cookies["userinfo"]["companycode"].ToString();
                ResultClass objress = co.fn_GetNameNumberStyle();
                if (objress.bStatus)
                {
                    eslist<CompanyMasterClass> OBJLISTS = objress.objData as eslist<CompanyMasterClass>;
                    if (OBJLISTS.Count > 0)
                    {
                        addfrm.Visible = true;
                        gridmain.Visible = false;
                        if (OBJLISTS[0].strname_style.ToString() == "PC")
                        {
                            txtGroupName.Text = misc.ToTitleCase(OBJLIST[0].strgroup_name);
                            txtGroupSname.Text = misc.ToTitleCase(OBJLIST[0].strgroup_sname);
                        }
                        if (OBJLISTS[0].strname_style.ToString() == "UC")
                        {
                            txtGroupName.Text = (OBJLIST[0].strgroup_name).ToUpper();
                            txtGroupSname.Text = (OBJLIST[0].strgroup_sname).ToUpper();
                            txtGroupName.Style.Add("text-transform", "uppercase");
                            txtGroupSname.Style.Add("text-transform", "uppercase");
                        }
                        if (OBJLISTS[0].strname_style.ToString() == "UG")
                        {
                            txtGroupName.Text = (OBJLIST[0].strgroup_name).ToUpper();
                            txtGroupSname.Text = (OBJLIST[0].strgroup_sname).ToUpper();
                        }
                    }
                }

                txtUnder.Text = OBJLIST[0].strunder;
                txtNotes.Text = OBJLIST[0].strnotes;
                for (int i = 0; i < OBJLIST.Count; i++)
                {
                    CompanyMasterClass cm = new CompanyMasterClass();
                    string p = OBJLIST[0].strcompany_code.ToString();
                    string t = string.Empty;
                    string code = string.Empty;
                    int count = 0;
                    string[] availcompanycode = p.Split(',');

                    foreach (string k in availcompanycode)
                    {
                        t = k.ToString();
                        code += "'" + t.ToString() + "'" + ",";

                        count++;
                    }
                    cm.strcompany_code = code.TrimEnd(',');

                    ResultClass objrest = cm.fn_GetCompanyListByCompanycode();

                    if (objres.bStatus)
                    {
                        eslist<CompanyMasterClass> OBJLISTS = objrest.objData as eslist<CompanyMasterClass>;
                        if (OBJLISTS.Count > 0)
                        {
                            // listboxsource.Items.Clear();
                            listboxdestination.DataTextField = "strcompany_name";
                            listboxdestination.DataValueField = "strcompany_code";
                            listboxdestination.DataSource = OBJLISTS;
                            listboxdestination.DataBind();
                        }
                    }



                    ListItem itemnature = new ListItem();
                    if (OBJLIST[i].strnature_of_group == "A")
                        itemnature.Text = "Assets";

                    else if (OBJLIST[i].strnature_of_group == "E")
                        itemnature.Text = "Expenses";
                    else if (OBJLIST[i].strnature_of_group == "I")
                        itemnature.Text = "Income";
                    else if (OBJLIST[i].strnature_of_group == "L")
                        itemnature.Text = "Liabilities";

                    // itemnature.Value = OBJLIST[i].igroup_id.ToString();

                    ddlNature.Items.Add(itemnature);


                    ListItem itemaffects = new ListItem();
                    if (OBJLIST[i].straffect_gross_profits == "N")
                        itemaffects.Text = "No";

                    else if (OBJLIST[i].straffect_gross_profits == "Y")
                        itemaffects.Text = "Yes";
                    //itemaffects.Value = OBJLIST[i].igroup_id.ToString();

                    ddlGrossProfit.Items.Add(itemaffects);

                    ListItem itemnett = new ListItem();
                    if (OBJLIST[i].strnett_drcr_report == "N")
                        itemnett.Text = "No";

                    else if (OBJLIST[i].strnett_drcr_report == "Y")
                        itemnett.Text = "Yes";
                    // itemnett.Value = OBJLIST[i].igroup_id.ToString();

                    ddlNett.Items.Add(itemnett);

                    ListItem itemlock = new ListItem();
                    if (OBJLIST[i].strlock_status == "N")
                        itemlock.Text = "No";

                    else if (OBJLIST[i].strlock_status == "Y")
                        itemlock.Text = "Yes";
                    // itemnett.Value = OBJLIST[i].igroup_id.ToString();

                    ddlNett.Items.Add(itemlock);

                }

            }
        }

    }
    catch
    {

    }
}

有任何想法吗?

谢谢,

4

1 回答 1

0

尝试使用Button editbtn = (Button)sender;而不是Button EditButton = (Button)gvGroupMaster.Rows[(((GridViewRow)(((Button)(sender)).Parent.BindingContainer))).RowIndex].FindControl("btnEdit");

于 2012-05-19T07:13:03.783 回答