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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get value from textchanged template in gridview

Status
Not open for further replies.

MzKitty

Programmer
Oct 28, 2003
254
US
Hi. I'm using vs2008. I have a gridview that has been set to allow editting on all rows for one template field. I am trying not to have a Edit/Update button. I would like the user to be able to enter the new amount and tab down to the next row. I am trying to catch the new amount on a textchanged event. My problem is that I can't seem to get the current row. I can find examples that use C+ but not vb.net code. Here is my code:

<asp:TemplateField HeaderText="NewInventory"
SortExpression="NewInventory">
<EditItemTemplate>
<asp:TextBox ID="NewInventory" runat="server" AutoPostBack="true"
Text='<%# Bind("NewInventory") %>'>
</asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:TextBox ID="NewInventory" runat="server"
OnTextChanged="UpdateNewQty" AutoPostBack="True"
Text='<%# Bind("NewInventory") %>'>
</asp:TextBox>
</ItemTemplate>
</asp:TemplateField>

Protected Sub UpdateNewQty(ByVal sender As Object, ByVal e As EventArgs)
Try
Dim strQty As String
Dim row As GridViewRow = (current row)
Dim txtQty As TextBox = (value in NewInventory textbox)
strQty = (value in NewInventory textbox)
Catch ex As Exception
End Try
End Sub

I appreciate any help that you can give me. I have been searching the web for code examples, but I'm getting greyer by the minute!
Thanks
Cathy
 
it will be very difficult, if not impossible to get this behavior from the gridview.
You would have an easier time implementing this user experience if you use html and jquery. a gridview is really only useful in the most basic scenarios.

Jason Meckley
Programmer

faq855-7190
faq732-7259
 
a textchanged event only fires on a postback, so it is basically the same as having an update button on each row, which you don't want. As Jason says you will need a javascript solution for this.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top