Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.


lost focus events in data grids

lost focus events in data grids

Hello all,

I was curious if anyone knows if there are any events, like the lost focus of text boxes, for individual cells in a datagrid.  I have a couple of functions that I call on the lost focus for any text boxes that have to be currency...which includes some validation.  I really need to call this for a datagrid that users will be entering new data into (or possibly editing data).  I would guess that there is something similar, since the grid dynamically creates new rows after you tab out of the last column.  Any ideas on how to reference this?

Thanks in advance,

- "The truth hurts, maybe not as much as jumping on a bicycle with no seat, but it hurts."

RE: lost focus events in data grids

You can use template column to insert ASP.NET validators so that the validation happens on the client side. Below is sample snippet.

<asp:datagrid id="productGrid" Width="100%" AutoGenerateColumns="False" Runat="server">
     <asp:TemplateColumn HeaderText="Product">            <ItemTemplate>                             <asp:Label id=productLabel runat="server" Width="100%" Text='<%# DataBinder.Eval(Container, "DataItem.Product") %>'>                     </asp:Label>                    </ItemTemplate>                        <EditItemTemplate>                         <asp:TextBox id=productTextBox style="TEXT-ALIGN: center" runat="server" Width="100%" Text='<%# DataBinder.Eval(Container, "DataItem.Product") %>' MaxLength="4">                                   </asp:TextBox>                        <asp:CompareValidator id="Comparevalidator2" runat="server" ErrorMessage="Product unit is not a valid number."
 ControlToValidate="productTextBox" Display="None" Operator="DataTypeCheck" Type="Integer"></asp:CompareValidator>                    <asp:RequiredFieldValidator id="Requiredfieldvalidator2" runat="server" ErrorMessage="Please enter the Product unit."
 ControlToValidate="productTextBox" Display="None"></asp:RequiredFieldValidator>            </EditItemTemplate>    

hope this helps!


RE: lost focus events in data grids

afaik you have an event called CurrentCellChanged.

"two wrongs don't make a right, but three lefts do" - the unknown sage

RE: lost focus events in data grids

ooo.....thanks guys....sorry I didn't thank you earlier, I just got back from being out of town.

I'll check out these options.

Thanks again,


- "The truth hurts, maybe not as much as jumping on a bicycle with no seat, but it hurts."

RE: lost focus events in data grids

Ok, I have tried doing the currentcellchanged event in our datagrid, but ended up getting stuck in an infinite loop (somewhat embarassing since I haven't done that in years).  In the currentcellchanged I used the column and row to establish if I wanted to call the validation code that I have written.  Is there any better way to handle it, than forcing a check for the column and row every time a user tabs through the grid?  Like, can I force it to call my validation code only when the user leaves a certain cell?

Any help would be appreciated.

thanks in advance,

- "The truth hurts, maybe not as much as jumping on a bicycle with no seat, but it hurts."

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close