开发者

How can i detect the Link button fire command-button in gridview control

开发者 https://www.devze.com 2023-03-18 00:46 出处:网络
I have a Strange issue that is i have develop a web application in one of the form i am using Gridview control with command button to view the row data.If in Gridview data have only record then link b

I have a Strange issue that is i have develop a web application in one of the form i am using Gridview control with command button to view the row data.If in Gridview data have only record then link button working fine if it is more than one record not working link buttons i can't under stand, this is very strange issue to me i have use !Page.IsPostBack also in pageload event,please help me .....

     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;

              开发者_StackOverflow中文版  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");
        }
    }

Here is my .aspx page

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


Try this:

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


Why don't you use a RESTful architecture to not save those parameters in Session and make pages kind'ev tightly coupled? Just create links named Info in your Grid instead of buttons (which post back data) with those parameters appended to the end of them as querystring. This is nicer approach and the result is the same.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号