BoundColumn TextBox

R

rn5a

A DataGrid displays 8 columns - ProductID, ProductName, Description,
Price, Quantity, Sub-Total, Edit & Delete. *Edit* is a
EditCommandColumn, *Delete* is a ButtonColumn & *Quantity* is a
BoundColumn. If the *Edit* link is clicked, the *Quantity* column
changes to the editable mode with a TextBox & the text under the
*Edit* column of the corresponding row gets replaced by 2 hyperlinks -
Update & Cancel.

In order to ensure that the width of the TextBox in the BoundColumn &
consequently the entire width of the DataGrid doesn't change
drastically when the DataGrid is in the editable mode, I added the
following sub on the DataGrid's OnPreRender event:

Sub ChangeWidth(ByVal obj As Object, ByVal ea As EventArgs)
If (dgCart.EditItemIndex > -1) Then
Dim tb As TextBox =
CType(dgCart.Items(dgCart.EditItemIndex).Cells(4).Controls(0),
TextBox)
tb.ID = "txtQty"
tb.Height = Unit.Pixel(20)
tb.Width = Unit.Pixel(30)
End If
End Sub

The above code does change the width of the TextBox under the
*Quantity* column when the DataGrid is in the editable mode.but when I
try to retrieve the quantity entered by the user from the *Quantity*
TextBox in the UpdateCommand event function of the DataGrid as shown
below:

===========================
Sub UpdateCart(obj As Object, ea As DataGridCommandEventArgs)
Dim iQty As Integer

iQty = CType(ea.Item.Cells(4).Controls(0), TextBox).Text
Response.Write("Quantity: " & iQty)
End Sub
===========================

the variable 'iQty' turns out be blank!

But if I get rid of the OnPreRender event function, then the
OnUpdateCommand event function (named 'UpdateCart') of the DataGrid
correctly retrieves the quantity entered by the user in the *Quantity*
TextBox.

What's causing this & how do I resolve this issue?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Dynamic BoundColumn 2
Update DataRow 2
BoundColumn 1
Cells.Controls 0
Input string was not in a correct format. 2
Controls 2
Get BoundColumn Data 0
OnPreRender 0

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top