Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

OnTextChanged event for a Textbox in a DataGrid

Posted on 2005-05-13
3
Medium Priority
?
661 Views
Last Modified: 2012-06-22
I have Textbox in a DataGrid. I want to use the OnTextChanged event for that
textbox to run code:

<asp:TextBox id=quantityTextBox runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Quantity") %>' ></asp:TextBox>

I would like the OnTextChanged of the above to run this Sub:

Private Sub grid_UpdateCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles grid.UpdateCommand
      Dim productId As String = grid.DataKeys(e.Item.ItemIndex)
      Dim quantity As String = CType(e.Item.FindControl("quantityTextBox"), TextBox).Text
      Try
         ShoppingCart.UpdateProductQuantity(productId, quantity)
         ...............
Can this be done? thanks
0
Comment
Question by:MikeMCSD
  • 2
3 Comments
 
LVL 23

Accepted Solution

by:
b1xml2 earned 2000 total points
ID: 13995684
<asp:TextBox id=quantityTextBox runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Quantity") %>' OnTextChanged="TextBox_Changed" ></asp:TextBox>

Public Sub TextBox_Changed(ByVal sender As Object,ByVal e As EventArgs)
      Dim ctl As System.Web.UI.Control = CType(sender,System.Web.UI.Control)
      Dim gridItem As DataGridItem = DirectCast(ctl.BindingContainer,DataGridItem)
      Dim args As New DataGridCommandEventArgs(gridItem,Nothing,New CommandEventArgs(Nothing,Nothing))
      grid_UpdateCommand(grid,args)
End Sub


Private Sub grid_UpdateCommand(ByVal source As Object,ByVal e As DataGridCommandEventArgs)
      'code
End Sub
0
 
LVL 23

Expert Comment

by:b1xml2
ID: 13995764
explanation is in order. I assure you there's no voodoo magic in the code =)

In the MSDN documentation, this is said of the BindingContainer:
"This member supports the .NET Framework infrastructure and is not intended to be used directly from your code." LOL!
 
Every control has this property called BindingContainer. The intellisense does not show it but it is there. Now the Binding Container is essentially the immediate/nearest parent that implements the INamingContainer. The implementation of the INamingContainer essentially means that any child controls within that control can only be accessed via the ControlCollection and never is visible via the Page.FindControls() method.

Hence, since this TextBox is inside a DataGridItem, the BindingContainer is the DataGridItem. We therefore can get the DataGridItem and pass it in the constructor of the DataGridCommandEventArgs and as they say, the rest is history.
0
 
LVL 16

Author Comment

by:MikeMCSD
ID: 13995922
Excellent! works great . .  thanks . .
I would have never figured that out in a million years!
Job well done . .
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Integration Management Part 2

575 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question