Editing a TextBox in a datagrid....

SteveoAtilla

Regular
Joined
Dec 22, 2004
Messages
80
Location
The Frozen Tundra
Hello!

I know there is a thread with information similar to this, but I want to be specific about the issue I am working on....

I have a datagrid with one Button Column, three Data Columns, and One Template Column containing a TextBox.

The Button Column has a button called UpdateQty, which, when clicked, will take the value the user types in the TextBox and update the SQL database that is bound to the datagrid with that value. I know I could use an editable datagrid, but I have the Stored Procedure which will, when the user enters "0" for the new value, actually delete the record.

I also have validation on the Button Click which verifies that first, there is something in the textbox, and further that it is numeric. What I need to do is, when the text in the box is not numeric, clear the TextBox. I can throw an error, but the box does not empty.

What command can be used to set the value of a Template TextBox? I know how to get the value:

Visual Basic:
[size=2][color=#0000ff]CType[/color][/size][size=2](e.Item.Cells(5).FindControl("txtQty"), TextBox)
[/size]

How can you put a value (blank, in my case) in that box?

Thanks,

Kahuna
 
can u call a function, in that check the value of the textbox and set it accordingly?

If u want examples of functions and how to check values like that..go to 4guysfromRolla, do a search for MorningZ posts. I had a similar question (but i wanted to check dates) and he recommanded using a function.
 
Here is the solution to the issue:

Visual Basic:
[size=2][color=#0000ff]CType[/color][/size][size=2](e.Item.Cells(4).FindControl("txtQty"), TextBox).Text = " "[/size]
[size=2]
[/size]

I use this code during validation. I am requiring numeric data, so if the entered value is non-numeric, I throw an alert window and clear the text box.

Kahuna
 
SteveoAtilla said:
Here is the solution to the issue:

Visual Basic:
[size=2][color=#0000ff]CType[/color][/size][size=2](e.Item.Cells(4).FindControl("txtQty"), TextBox).Text = " "[/size][size=2]
[/size]

I use this code during validation. I am requiring numeric data, so if the entered value is non-numeric, I throw an alert window and clear the text box.

Kahuna
Alternately, a variable can be created and used to avoid the CType command:

Visual Basic:
[size=2][color=#0000ff]Dim[/color][/size][size=2] box [/size][size=2][color=#0000ff]As[/color][/size][size=2] TextBox[/size]
[size=2]box = [/size][size=2][color=#0000ff]CType[/color][/size][size=2](e.Item.Cells(4).FindControl("txtQty"), TextBox)[/size]
[size=2]box.text = " "
[/size]

This results in the same thing, but would be cleaner if you repeatedly needed to refer to the textbox.

Kahuna
 
Back
Top