我如何检测链接按钮火命令按钮在网格视图控制

本文关键字:按钮 命令 网格 控制 视图 链接 何检测 检测 | 更新日期: 2023-09-27 18:01:27

我有一个奇怪的问题,那就是我已经开发了一个web应用程序的形式之一,我使用Gridview控件与命令按钮来查看行数据。如果在Gridview数据中只有记录,那么链接按钮工作正常,如果它不止一个记录不工作链接按钮,我无法理解,这对我来说是非常奇怪的问题,我有使用!IsPostBack也在页面加载事件,请帮助我.....

     protected void grdmanageloans_RowCommand(object sender, GridViewCommandEventArgs e)
    {
       if (e.CommandName == "Info") 
        {
            try
        {
            int loanid = Convert.ToInt32(e.CommandArgument);
            Session["Loanid"] = loanid;
            Session["Edit"] = "Edit";
            TabContainer1.ActiveTabIndex = 1;
            Session["TabContainer1"] ="loantab";
            Session["Tabloan"] = "Tabloan";
            Response.Redirect("Mortgageclient.aspx");
        }
        catch { }
                    }
       if (e.CommandName == "Delete")
        {
            try
            {
                int LoanId = Convert.ToInt32(e.CommandArgument);
                var PmtScheduleHistory = from del in mortgageentity.Pmt_Schedule_History where del.Loan.Loan_ID == LoanId select del;
                var LoanPayment = from del in mortgageentity.Payments where del.Loan_ID == LoanId select del;
                if (PmtScheduleHistory.Count() > 0)
                {
                    var DelPmtScheduleHistory = (from del in mortgageentity.Pmt_Schedule_History where del.Loan.Loan_ID == LoanId select del).First();
                    mortgageentity.DeleteObject(DelPmtScheduleHistory);
                    mortgageentity.SaveChanges();
                }
                var Getpayments = from db in mortgageentity.Payments where db.Loan_ID == LoanId select db;
                if (Getpayments.Count() > 0)
                {
                    foreach (var i in Getpayments)
                    {
                        mortgageentity.DeleteObject(i);
                        mortgageentity.SaveChanges();
                    }
                } 
                if (LoanPayment.Count() > 0)
                {
                    var DelPmtScheduleHistory = (from del in mortgageentity.Payments where del.Loan_ID == LoanId select del.Payment_Status.PaymentStatus_ID).First();
                    mortgageentity.DeleteObject(DelPmtScheduleHistory);
                    mortgageentity.SaveChanges();
                }
                var deletedata = (from del in mortgageentity.Loans where del.Loan_ID == LoanId select del).First();
                mortgageentity.DeleteObject(deletedata);
                mortgageentity.SaveChanges();
                BindData();
            }
            catch { }
        }
        if (e.CommandName == "AddNewloan")
        {
            Session["Addnewloan"] = "Addloan";
            Response.Redirect("Information.aspx");
        }
    }

这是我的。aspx页面

     <asp:GridView ID="grdmanageloans" runat="server" AutoGenerateColumns="False" AllowSorting="True"
                                                            GridLines="Both" PageSize="10" AllowPaging="true" OnRowCommand="grdmanageloans_RowCommand"
                                                            OnSelectedIndexChanged="grdmanageloans_SelectedIndexChanged" ShowFooter="true"
                                                            OnPageIndexChanging="grdmanageloans_PageIndexChanging" OnRowDataBound="grdmanageloans_Rowdatabound">
                                                            <AlternatingRowStyle BackColor="#F3F9FB" />
                                                            <RowStyle BackColor="#FEFEFE" VerticalAlign="Top" />
                                                            <HeaderStyle BackColor="#F3F9FB" />
                                                            <FooterStyle BackColor="#F3F9FB" />
                                                            <RowStyle Wrap="False" />
                                                            <HeaderStyle ForeColor="#1F476F" />
                                                            <Columns>
                                                                <asp:TemplateField HeaderText="LoanID" Visible="true">
                                                                    <ItemStyle HorizontalAlign="Center" />
                                                                    <ItemTemplate>
                                                                        <asp:Label ID="lblloanid" runat="server" Text='<%# Bind("Loan_ID") %>'></asp:Label>
                                                                    </ItemTemplate>
                                                                </asp:TemplateField>
                                                                <asp:TemplateField HeaderText="Loan Number">
                                                                    <ItemStyle HorizontalAlign="Center" />
                                                                    <ItemTemplate>
                                                                        <asp:Label ID="lblLoanNumber" runat="server" Text='<%# Bind("LoanNumber") %>'></asp:Label>
                                                                    </ItemTemplate>
                                                                </asp:TemplateField>
                                                                <asp:TemplateField HeaderText="Month Pay Amt" HeaderStyle-Wrap="false">
                                                                    <ItemStyle HorizontalAlign="Center" />
                                                                    <ItemTemplate>
                                                                        <asp:Label ID="lblMonthPayAmt" runat="server" Text='<%#Getammount(Eval("MonthPayAmt","{0:F2}")) %>'></asp:Label>
                                                                    </ItemTemplate>
                                                                </asp:TemplateField>
                                                                <asp:TemplateField HeaderText="Address">
                                                                    <ItemStyle HorizontalAlign="Center" />
                                                                    <ItemTemplate>
                                                                        <asp:Label ID="lblpropaddress" runat="server" Text='<%# Bind("PropAddress") %>'></asp:Label>
                                                                    </ItemTemplate>
                                                                </asp:TemplateField>
                                                                <asp:TemplateField HeaderText="City">
                                                                    <ItemStyle HorizontalAlign="Center" />
                                                                    <ItemTemplate>
                                                                        <asp:Label ID="lblpropcity" runat="server" Text='<%# Bind("PropCity") %>'></asp:Label>
                                                                    </ItemTemplate>
                                                                </asp:TemplateField>
                                                                <asp:TemplateField HeaderText="State">
                                                                    <ItemStyle HorizontalAlign="Center" />
                                                                    <ItemTemplate>
                                                                        <asp:Label ID="lblpropstate" runat="server" Text='<%# Bind("PropState") %>'></asp:Label>
                                                                    </ItemTemplate>
                                                                </asp:TemplateField>
                                                                <asp:TemplateField HeaderText="ClientID" Visible="false">
                                                                    <ItemStyle HorizontalAlign="Center" />
                                                                    <ItemTemplate>
                                                                        <asp:Label ID="lblclientid" runat="server" Text='<%# Bind("Client_ID") %>'></asp:Label>
                                                                    </ItemTemplate>
                                                                </asp:TemplateField>
                                                                <asp:TemplateField>
                                                                    <ItemStyle HorizontalAlign="Center" />
                                                                    <ItemTemplate>

                                                                      <asp:LinkButton ID="lnkeinfo" runat="server" CausesValidation="false" CommandName="Info"
                                                                            CommandArgument='<%#Eval("Loan_ID")%>'>Information</asp:LinkButton>
                                                                    </ItemTemplate>
                                                               </asp:TemplateField>
                                                            </Columns>
                                                        </asp:GridView>

我如何检测链接按钮火命令按钮在网格视图控制

试试这个:

 <asp:LinkButton ID="lnkeinfo" runat="server" CausesValidation="false" CommandName="Info"
                                                                            CommandArgument='<%# Bind("Loan_ID") %>'>Information</asp:LinkButton>

为什么不使用RESTful架构来不将这些参数保存在Session中并使页面紧密耦合呢?只需在您的网格中创建名为Info的链接,而不是按钮(该按钮返回数据),这些参数附加到它们的末尾为querystring。这是一个更好的方法,结果是一样的。