如何在javascript中的rowcommand事件上验证gridview的控件

如何在javascript中的rowcommand事件上验证gridview的控件

问题描述:

您好,我正在使用gridview并在其行命令事件中将文本框数据保存到数据库中...但是当我点击行命令的链接按钮时,它未验证文本框或下拉列表是否有值...请发布帮助我..



< asp:GridView ID =grdBillingrunat =serverAllowPaging =trueAutoGenerateColumns =falseOnRowCommand = grdBilling_RowCommand

CssClass =table-shortWidth =75%GridLines =noneEmptyDataText =无数据可用。>

< Columns>

< asp:TemplateField HeaderText =Sr No。>

< ItemTemplate>

< asp:Label ID = lblSrNorunat =server><%#Container.DataItemIndex + 1%>< / asp:Label>

< / ItemTemplate>

&lt ; / asp:TemplateField>

< asp:TemplateField HeaderText =Brand>

< ItemT emplate>

< asp:Label ID =lblBrandIdrunat =serverVisible =falseText ='<%#DataBinder.Eval(Container.DataItem,BrandId)% >'>< / asp:标签>

< asp:标签ID =lblBrandrunat =serverText ='<%#DataBinder.Eval(Container.DataItem, BrandName)%>'>< / asp:标签>

< / ItemTemplate>

< / asp:TemplateField>

< asp:TemplateField HeaderText =Product>

< ItemTemplate>

< asp:Label ID =lblProdIdrunat =server Visible =falseText ='<%#DataBinder.Eval(Container.DataItem,ProductId)%>'>< / asp:Label>

< asp:Label ID =lblProductrunat =serverText ='<%#DataBinder.Eval(Container.DataItem,ProductName)%>'>< / asp:Label>

< / ItemTemplate>

< / asp:TemplateField>

< asp:TemplateField HeaderText =Bill Type>

< ItemTemplate>

< asp:DropDownList ID =ddlBillTyperunat =server>

< asp:ListItem Text = - Select--Value =0>< / asp:ListItem&gt ;

< asp:ListItem Text =月末票据值=1>< / asp:ListItem>

< asp:ListItem Text = CPP BillsValue =2>< / asp:ListItem>

< asp:ListItem Text =Cartridge BillsValue =3>< / asp:ListItem&gt ;

< / asp:DropDownList>

< / ItemTemplate>

< / asp:TemplateField>

< asp:TemplateField HeaderText =结算日期>

< ItemTemplate>

< asp:TextBox ID =txtBillingDaterunat =serverstyle =vertical-align:middlewidth =150pxonfocus =this.blur()CssClass =datePickerTextBox>< / asp:TextBox>

< / ItemTemplate>

< / asp:TemplateField>

< asp:TemplateField HeaderText =Invoice No>

< ItemTemplate>

< asp:TextBox ID =txtInvoiceNorunat =server>< / asp:TextBox>

< / ItemTemplate>

< / asp:TemplateField>

< asp:TemplateField HeaderText =Grnerate Bill>

< ItemTemplate>

< asp:Button ID =btnPayment runat =serverText =生成BillCommandName =cPayCommandArgument ='<%#((GridViewRow)Container).RowIndex%>'/>

< / ItemTemplate>

< / asp:TemplateField>

< / Columns>

< / asp:GridView>

Hello, I am using gridview and on its row command event i m saving the textbox data into database...But when i am clicking on link button for row command its not validating the textbox or dropdownlist has value or not..Please Help me with this..

<asp:GridView ID="grdBilling" runat="server" AllowPaging="true" AutoGenerateColumns="false" OnRowCommand="grdBilling_RowCommand"
CssClass="table-short" Width="75%" GridLines="none" EmptyDataText="No data available.">
<Columns>
<asp:TemplateField HeaderText="Sr No.">
<ItemTemplate>
<asp:Label ID="lblSrNo" runat="server"><%# Container.DataItemIndex + 1 %></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Brand">
<ItemTemplate>
<asp:Label ID="lblBrandId" runat="server" Visible="false" Text='<%#DataBinder.Eval(Container.DataItem, "BrandId") %>'></asp:Label>
<asp:Label ID="lblBrand" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "BrandName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Product">
<ItemTemplate>
<asp:Label ID="lblProdId" runat="server" Visible="false" Text='<%#DataBinder.Eval(Container.DataItem, "ProductId") %>'></asp:Label>
<asp:Label ID="lblProduct" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "ProductName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Bill Type">
<ItemTemplate>
<asp:DropDownList ID="ddlBillType" runat="server">
<asp:ListItem Text="--Select--" Value="0"></asp:ListItem>
<asp:ListItem Text="Month End Bills" Value="1"></asp:ListItem>
<asp:ListItem Text="CPP Bills" Value="2"></asp:ListItem>
<asp:ListItem Text="Cartridge Bills" Value="3"></asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Billing Date">
<ItemTemplate>
<asp:TextBox ID="txtBillingDate" runat="server" style="vertical-align:middle" width="150px" onfocus="this.blur()" CssClass="datePickerTextBox"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Invoice No">
<ItemTemplate>
<asp:TextBox ID="txtInvoiceNo" runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Grnerate Bill">
<ItemTemplate>
<asp:Button ID="btnPayment" runat="server" Text="Generate Bill" CommandName="cPay" CommandArgument='<%#((GridViewRow)Container).RowIndex%>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

您可以将onClientClick添加到btnPayment,例如



You can add a OnClientClick to the btnPayment like

<asp:button id="btnPayment" runat="server" text="Generate Bill" commandname="cPay" commandargument="<%#((GridViewRow)Container).RowIndex%>" onclientclick="return validateControls(this);"></asp:Button>





然后验证骗局客户端上的trols如:





and then validate the controls on client side like:

function validateControls(rowObject)
{
    // validate this row controls here
    if(valid){
        return true;
    } else {
        return false;
    }
}





更多详情 here。 [ ^ ]



我希望这可以帮助你入门!



More details here.[^]

I hope this would help you getting started!