从按钮Click事件中的GridView中的TextBox获取无效值

时间:2015-11-19 06:06:50

标签: javascript asp.net .net

我在GridView gvInvoice <ItemTemplate>中有一个Panel,其中GridView gvInvoiceDetails包含另一个<asp:GridView ID="gvInvoice" runat="server" AutoGenerateColumns="false" CssClass="Grid" ShowFooter="true" OnPageIndexChanging="gvInvoice_PageIndexChanging" OnRowEditing="gvInvoice_RowEditing" OnRowDeleting="gvInvoice_RowDeleting" OnRowCancelingEdit="gvInvoice_RowCancelingEdit" OnRowUpdating="gvInvoice_RowUpdating" DataKeyNames="Invoice_Description_Id" OnRowDataBound="gvInvoice_RowDataBound"> <Columns> <asp:TemplateField> <ItemTemplate> <img alt="" style="cursor: pointer" src="Images/plus.png" /> <asp:Panel ID="pnlOrders" runat="server" Style="display: none"> <asp:GridView ID="gvInvoiceDetails" runat="server" AutoGenerateColumns="false" ShowFooter="true" CssClass="ChildGrid" OnRowCommand="gvInvoiceDetails_RowCommand" OnRowDataBound="gvInvoiceDetails_RowDataBound" OnPageIndexChanging="gvInvoiceDetails_PageIndexChanging" OnRowEditing="gvInvoiceDetails_RowEditing" OnRowDeleting="gvInvoiceDetails_RowDeleting" OnRowCancelingEdit="gvInvoiceDetails_RowCancelingEdit" OnRowUpdating="gvInvoiceDetails_RowUpdating" DataKeyNames="Invoice_Detail_Id"> <Columns> <asp:TemplateField HeaderText="Description" ItemStyle-Width="150px"> <ItemTemplate> <asp:Label ID="lblDescription" runat="server" Text='<%#Eval("Invoice_Detail")%>'></asp:Label> </ItemTemplate> <EditItemTemplate> <asp:TextBox ID="txtEditDetailDescription" TextMode="MultiLine" runat="server"></asp:TextBox> </EditItemTemplate> <FooterTemplate> <asp:TextBox ID="txtAddDetailDescription" TextMode="MultiLine" runat="server"></asp:TextBox> </FooterTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Rate" ItemStyle-Width="150px"> <ItemTemplate> <asp:Label ID="lblRate" runat="server" Text='<%#Eval("Invoice_Rate")%>'></asp:Label> </ItemTemplate> <EditItemTemplate> <asp:TextBox ID="txtEditDetailRate" runat="server"></asp:TextBox> </EditItemTemplate> <FooterTemplate> <asp:TextBox ID="txtAddDetailRate" runat="server"></asp:TextBox> </FooterTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Amount" ItemStyle-Width="150px"> <ItemTemplate> <asp:Label ID="lblAmount" runat="server" Text='<%#Eval("Invoice_Amount")%>'></asp:Label> </ItemTemplate> <EditItemTemplate> <asp:TextBox ID="txtEditDetailAmount" runat="server"></asp:TextBox> </EditItemTemplate> <FooterTemplate> <asp:TextBox ID="txtAddDetailAmount" runat="server"></asp:TextBox> </FooterTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Action"> <EditItemTemplate> <asp:Button ID="btnUpdate" CommandName="Update" runat="server" Text="Update" /> <asp:Button ID="btnCancel" CommandName="Cancel" runat="server" Text="Cancel" /> </EditItemTemplate> <ItemTemplate> <asp:Button ID="btnEdit" CommandName="Edit" runat="server" Text="Edit" /> <asp:Button ID="btnDelete" CommandName="Delete" runat="server" Text="Delete" OnClientClick="return DeleteConfirmation()" /> </ItemTemplate> <FooterTemplate> <asp:Button ID="btnAddInvoiceDetails" CommandName="Add" OnClick="btnAddInvoiceDetails_Click" runat="server" Text="Add" /> </FooterTemplate> </asp:TemplateField> </Columns> </asp:GridView> </asp:Panel> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Description" ItemStyle-Width="577px"> <ItemTemplate> <asp:Label ID="lblDescription" runat="server" Text='<%#Eval("Invoice_Description")%>'></asp:Label> </ItemTemplate> <EditItemTemplate> <asp:TextBox ID="txtEditDescription" runat="server" TextMode="MultiLine"></asp:TextBox> </EditItemTemplate> <FooterTemplate> <asp:TextBox ID="txtFooterDescription" runat="server" TextMode="MultiLine"></asp:TextBox> </FooterTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Amount" ItemStyle-Width="450px"> <ItemTemplate> <asp:Label ID="lblInvoiceAmount" runat="server"></asp:Label> </ItemTemplate> <EditItemTemplate> <asp:Label ID="lblEditamount" runat="server"></asp:Label> </EditItemTemplate> <FooterTemplate> <asp:Label ID="lblFooterAmount" runat="server"></asp:Label> </FooterTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Action"> <EditItemTemplate> <asp:Button ID="btnUpdate" CommandName="Update" runat="server" Text="Update" /> <asp:Button ID="btnCancel" CommandName="Cancel" runat="server" Text="Cancel" /> </EditItemTemplate> <ItemTemplate> <asp:Button ID="btnEdit" CommandName="Edit" runat="server" Text="Edit" /> <asp:Button ID="btnDelete" CommandName="Delete" runat="server" Text="Delete" OnClientClick="return DeleteConfirmation()" /> </ItemTemplate> <FooterTemplate> <asp:Button ID="btnAddEName" OnClick="btnAddEName_Click" runat="server" Text="Add" /> </FooterTemplate> </asp:TemplateField> </Columns> </asp:GridView> ,如下面的代码所示。

ASPX代码

txtAddDetailDescription

我的问题是,当我尝试从txtAddDetailRate txtAddDetailAmount&amp;按钮点击事件btnAddInvoiceDetails_Click上的,我在所有三个值之前得到,,我无法找到我从哪里获得,我试过搜索可能是我有将,放在代码中但无法找到任何代码。因此,如果有人可以帮助我找到我所在的位置.cs将会非常有帮助。我的protected void btnAddInvoiceDetails_Click(object sender, EventArgs e) { Button btn = (Button)sender; GridViewRow gvInvoiceDetailsRow = (GridViewRow)btn.NamingContainer; GridView gvInvoiceDetails = (GridView)gvInvoiceDetailsRow.NamingContainer; TextBox Description = ((TextBox)gvInvoiceDetails.FooterRow.FindControl("txtAddDetailDescription")); TextBox DetailRate = ((TextBox)gvInvoiceDetails.FooterRow.FindControl("txtAddDetailRate")); TextBox DetailAmount = ((TextBox)gvInvoiceDetails.FooterRow.FindControl("txtAddDetailAmount")); GridViewRow gvInvoiceRow = (GridViewRow)gvInvoiceDetails.NamingContainer; GridView gvInvoice = (GridView)gvInvoiceRow.NamingContainer; string RequestId = Convert.ToString(gvInvoice.DataKeys[gvInvoiceRow.RowIndex].Value); int Invoice_Description_Id = Convert.ToInt16(RequestId); SqlParameter[] spa = new SqlParameter[5]; spa[0] = new SqlParameter("@Type", 2); spa[1] = new SqlParameter("@Invoice_Detail", Description.Text); spa[2] = new SqlParameter("@Invoice_Rate", Convert.ToDecimal(DetailRate.Text)); spa[3] = new SqlParameter("@Invoice_Amount", Convert.ToDecimal(DetailAmount.Text)); spa[4] = new SqlParameter("@Invoice_Description_Id", Invoice_Description_Id); int k = gs.Sp_InsertUpdateDelete("Sp_Invoice_Detail", spa); if (k > 0) { Response.Write("Record Inserted successfully"); FillDetailGrid(gvInvoiceDetails, Invoice_Description_Id); } } 代码如下。

CS代码

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
     <script type="text/javascript">
        $("[src*=plus]").live("click", function () {
            $(this).closest("tr").after("<tr><td></td><td colspan = '999'>" + $(this).next().html() + "</td></tr>")
            $(this).attr("src", "images/minus.png");
        });
        $("[src*=minus]").live("click", function () {
            $(this).attr("src", "Images/plus.png");
            $(this).closest("tr").next().remove();
        });
    </script>

的JavaScript

a = {
    display: function (n){
        console.log("I am inside display method");
        n();
    }
}
function name(a,str2)
{
    a.display(function (){
        console.log(str2);
    })
}
name(a, 'ddd');

0 个答案:

没有答案