Note the OnEditCommand just sets up the grid to allow editing of a row, it
will not perform any validation.  The OnUpdate command DOES cause the
validation, as it is an attempt to save the changes to the row.  You can use
the OnEditCommand to set up any validation you want to perform when the
Update button is pressed.

You can add a clientside script that validates the proper control using the

RegisterClientScriptBlock method (member of the Page class)

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfSystemWebUIPageClassRegisterClientScriptBlockTopic.asp

In your dgBook_Edit handler you can get the client ID that will be used by
text box created in the column when the row is in Edit mode.  You can then
use that write your javascript to the page using RegisterClientScriptBlock.
For example...

Dim sClientID as string
sClientID = e.Item.Cells(1).Controls(0).ClientID '1 is the column ordinal

Then write out your validation script using RegisterClientScriptBlock.

Of course, that's the hard way to do it.  A simpler way is convert the bound
column  BookName to a template column and add a RequiredField validation
control in the EditItemTemplate. Then all you do is set it to validate the
text box in the column. When the user hits the Update button, standard
ASP.NET validation is used. For example, this would display in error in a
Validation sumamry control if the book name was not supplied.

        <asp:TemplateColumn SortExpression="BookName" HeaderText="Book Name">
                <ItemTemplate>
                        <asp:Label runat="server" ID="lblBookName"></asp:Label>
                </ItemTemplate>
                <EditItemTemplate>
                        <asp:TextBox runat="server" ID="txtBookName"></asp:TextBox>
                        <asp:RequiredFieldValidator Runat="server"
ControlToValidate="txtBookName" Display="None" ErrorMessage="Book Name is
required." />
                </EditItemTemplate>
        </asp:TemplateColumn>

The one downside to this approach is that you have to do your own filling of
the controls in the grid's ItemDataBound event handler.

HTH,

Dean Fiala
-----------------------------
Very Practical Software, Inc.
http://www.vpsw.com/links.aspx




-----Original Message-----
From: askaspnetq [mailto:[EMAIL PROTECTED]
Sent: Tuesday, May 18, 2004 11:55 AM
To: [EMAIL PROTECTED]
Subject: [AspNetAnyQuestionIsOk] Validation check on edit DataGrid


I have a user control content a DateGrid, which has
Edit/Update/Cancel function on it
Code:
<asp:DataGrid id="dgBook"
                  DataKeyField="sysID"
                  OnEditCommand   = "dgBook_Edit"
                  OnCancelCommand = "dgBook_Cancel"
                  OnUpdateCommand = "dgBook_Update"
                  OnDeleteCommand = "dgBook_Delete"
                  AutoGenerateColumns= "False">
<HeaderStyle ForeColor="White"  HorizontalAlign="Center" />
<Columns>
    <asp:BoundColumn  DataField="sysID"  ReadOnly = "true" />
    <asp:BoundColumn  HeaderText="Book Name" DataField="BookName" />
    <asp:EditCommandColumn ItemStyle-HorizontalAlign= "center"
         EditText="Edit"   CancelText="Cancel"
         UpdateText="Update"   HeaderText="Edit Book" />
    <asp:ButtonColumn Text="Delete"
         CommandName="Delete"  HeaderText = "Delete Book"/>
</Columns>
</asp:DataGrid>

I want add client side isblank() javascript validation check for edit
book name.
I had two questions:
1. Because it is user control. It will load in a form with other
   elements. How can I define the edit column?
2. DataGrid's OnEditCommand will run at server, is not a submit
   event. How can I add client side validation check on it?

Thank you in advance.


Jennifer






Yahoo! Groups Links









------------------------ Yahoo! Groups Sponsor ---------------------~-->
Yahoo! Domains - Claim yours for only $14.70
http://us.click.yahoo.com/Z1wmxD/DREIAA/yQLSAA/saFolB/TM
---------------------------------------------------------------------~->

 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
     http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/

<*> To unsubscribe from this group, send an email to:
     [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
     http://docs.yahoo.com/info/terms/
 

Reply via email to