Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

lost focus events in data grids

Status
Not open for further replies.

kmfna

MIS
Joined
Sep 26, 2003
Messages
306
Location
US
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,
Kevin

- "The truth hurts, maybe not as much as jumping on a bicycle with no seat, but it hurts.
 
Hi!
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">
<Columns>
<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>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>

hope this helps!

meydz
 
afaik you have an event called CurrentCellChanged.

--------------------------
"two wrongs don't make a right, but three lefts do" - the unknown sage
 
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,

Kevin

- "The truth hurts, maybe not as much as jumping on a bicycle with no seat, but it hurts.
 
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,
Kevin

- "The truth hurts, maybe not as much as jumping on a bicycle with no seat, but it hurts.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top