4
<asp:TemplateField HeaderText="Quantity">
    <ItemTemplate>
        <asp:Label ID="lbl_quantity" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"quantity") %>'>
        </asp:Label>

    </ItemTemplate>

    <EditItemTemplate>
        <asp:TextBox runat="server" ID="txtquantity" Width="90px" onkeypress="return validatenumerics(event);" Text='<%# DataBinder.Eval(Container.DataItem,"quantity") %>'></asp:TextBox>
        <asp:RequiredFieldValidator ID="RFquantity" runat="server" ControlToValidate="txtquntity" Display="None" ErrorMessage="This field is required value" ValidationGroup="quantity">
        </asp:RequiredFieldValidator>
        <ajaxToolkit:ValidatorCalloutExtender ID="VCquantity" runat="Server" TargetControlID="RFquantity"/>

    </EditItemTemplate>
</asp:TemplateField>

I want to shows an javascript message , if text box is empty..i tried this code. for validation purpose required field validation is added.then "edit" button is not fired..please help me.

This is my grid with edit ,update ,cancel and cancel button

  protected void gvproducts_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
    gvproducts.EditIndex = -1;
    grid();

}
protected void gvproducts_RowEditing(object sender, GridViewEditEventArgs e)
{
    gvproducts.EditIndex = e.NewEditIndex;
    grid();
}
protected void gvproducts_RowUpdating(object sender, GridViewUpdateEventArgs e)
{

    TextBox txtquantity = (TextBox)gvproducts.Rows[e.RowIndex].Cells[4].Controls[1];

    int st = Convert.ToInt32(gvproducts.DataKeys[e.RowIndex].Values[0].ToString());


    objsupplyPL.quantity = Convert.ToInt32(txtquantity.Text.ToString());

    objsupplyPL.sno = st;
    DataTable scmpurchase = new DataTable();
    scmpurchase = objsupplyBAL.updatepurchase(objsupplyPL);

    ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "UpdateDetails", "alert('Update Successful');", true);
    gvproducts.EditIndex = -1;
    grid();
}
3

2 Answers 2

1

What you could do is add a ValidationSummery with ShowMessageBox and a ValidationGroup just above the GridView

<asp:ValidationSummary ID="ValidationSummary1" runat="server" ShowMessageBox="true" ShowSummary="false" ValidationGroup="quantity" />

And change the TemplateField to this (make sure EnableClientScript=true) and make sure the EditButton has same validationgroup

<asp:TemplateField HeaderText="Quantity">
    <ItemTemplate>
        <asp:Label ID="lbl_quantity" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"quantity") %>' />
    </ItemTemplate>
    <EditItemTemplate>
        <asp:TextBox runat="server" ID="txtquantity" Width="90px" Text='<%# DataBinder.Eval(Container.DataItem,"quantity") %>' ValidationGroup="quantity"  />
        <asp:RequiredFieldValidator ID="RFquantity" runat="server" ControlToValidate="txtquantity" EnableClientScript="true"  Display="None" ErrorMessage="This field is required value" ValidationGroup="quantity" />
    </EditItemTemplate>
</asp:TemplateField>        
<asp:CommandField ShowEditButton="True" ValidationGroup="quantity" />
Sign up to request clarification or add additional context in comments.

2 Comments

I added validation summary as you like...but it's not effect edit button
How does your EditButton declaration looks like?
1

just add a class to your TextBox and find the control using class finder with jquery. Then, you can check whether the TextBox.val() is empty or not using the javascript function.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.