Click here to Skip to main content
15,878,959 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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>
Posted
Updated 12-Oct-15 3:32am
v2
Comments
Sreekanth Mothukuru 12-Oct-15 10:00am    
Have you tried adding validation logic for a taxtbox on its "onblur" client side event ?
It should not be on focus.

1 solution

You can add a OnClientClick to the btnPayment like

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


and then validate the controls on client side like:

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


More details here.[^]

I hope this would help you getting started!
 
Share this answer
 
v3
Comments
Member 11864926 13-Oct-15 1:35am    
Thank you so much...it worked for me..thanks once again
Palash Mondal_ 13-Oct-15 1:38am    
Glad it helped!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900