schwientekd
asked on
ASP.NET gridview select textbox on focus
I have a gridview on an asp.net webpage which has textboxes as template fields throughout each column. When the gridview loads most of the textboxes are prepopulated with text. I would like to be able to click on the textbox and have the text be selected (highlighted) so that when a change needs to be made the visitor does not need to select the text by dragging the mouse or double clicking on it.
I have tried using javascript to accomplish this by placing the following code into the page for a textbox I call tbTest which is OUTSIDE of the gridview (just for testing purposes).
'This is inserted into the source code of the aspx page
<script type="text/javascript" language="javascript">
function selectText() {
document.getElementById("< %=tbTest.C lientID %>").select();
}
</script>
'This line is in the page load event of the code behind
tbTest.Attributes.Add("onf ocus", "selectText();")
This works on the tbTest textbox but I do not know how to make this work for a textbox in the gridview. I can access the textboxes by using the following line in the RowDataBound event.
Dim testString As String = TryCast(e.Row.FindControl( "tbGridCol 1"), TextBox).Text()
Can I add something to the RowDataBound event to accomplish this or is there another method anyone knows of?
I have tried using javascript to accomplish this by placing the following code into the page for a textbox I call tbTest which is OUTSIDE of the gridview (just for testing purposes).
'This is inserted into the source code of the aspx page
<script type="text/javascript" language="javascript">
function selectText() {
document.getElementById("<
}
</script>
'This line is in the page load event of the code behind
tbTest.Attributes.Add("onf
This works on the tbTest textbox but I do not know how to make this work for a textbox in the gridview. I can access the textboxes by using the following line in the RowDataBound event.
Dim testString As String = TryCast(e.Row.FindControl(
Can I add something to the RowDataBound event to accomplish this or is there another method anyone knows of?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
<script type="text/javascript" language="javascript">
function selectText() {
document.getElementById("<
}
</script>