Hi there,
Example to move caret to the end:
--begin code--
<asp:GridView runat="server" ID="list" OnRowEditing="l ist_RowEditing"
AutoGenerateCol umns="false" DataKeyNames="i d">
<Columns>
<asp:TemplateFi eld>
<ItemTemplate >
<%# Eval("id") %>
</ItemTemplate>
<EditItemTempla te>
<asp:TextBox runat="server" ID="txtName" Text='<%# Bind("id") %>'/>
</EditItemTemplat e>
</asp:TemplateFie ld>
<asp:TemplateFi eld>
<ItemTemplate >
<%# Eval("name") %>
</ItemTemplate>
<EditItemTempla te>
<%--onfocus is an 'exapndo' - it is not a property of the textbox but it
will be rendered--%>
<asp:TextBox runat="server" ID="txtName" Text='<%# Bind("name") %>'
onfocus="MoveCu rsorToTheEnd(th is)"/>
</EditItemTemplat e>
</asp:TemplateFie ld>
<asp:CommandFie ld ShowEditButton= "true"/>
</Columns>
</asp:GridView>
<script type="text/javascript">
function MoveCursorToThe End(input)
{
var position = input.value.len gth;
if (/gecko/i.test(navigato r.userAgent))
{
input.setSelect ionRange(positi on, position);
}
else
{
var textRange = input.createTex tRange();
textRange.colla pse(true);
textRange.moveS tart("character ", position);
textRange.moveE nd("character" , 0);
textRange.selec t();
}
}
</script>
--end code --
--
Milosz Skalecki
MCAD
"Blasting Cap" wrote:
I have a couple fields (one varchar 20, one varchar 500) for a PO Number
& a comment field on a datagrid.
Once they're entered, a user can edit them and make changes to them.
However, when they click edit on them, the boxes are populated, and when
you click in the box, the cursor stays wherever you click it, when what
I want to do is to have it go to the end of the string that's in the
text box.
I'd like the HOME and the END keys to take you to the beginning and end
of the text, but they take you from the beginning of the text to the end
of the field - 20 or 500 characters away.
I thought a trim on the fields would do this, but it hasn't.
Is there something in the formatting expressions I need to have that I
don't?
How can I do this?
BC