Edit function on Datagrid

B

Blasting Cap

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
 
B

bruce barker

this is standard browser behavior. you can write client script to change
it if you want.

-- bruce (sqlwork.com)
 
G

Guest

Hi there,

Example to move caret to the end:

--begin code--

<asp:GridView runat="server" ID="list" OnRowEditing="list_RowEditing"
AutoGenerateColumns="false" DataKeyNames="id">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<%# Eval("id") %>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" ID="txtName" Text='<%# Bind("id") %>'/>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<%# Eval("name") %>
</ItemTemplate>
<EditItemTemplate>
<%--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="MoveCursorToTheEnd(this)"/>
</EditItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowEditButton="true"/>
</Columns>

</asp:GridView>

<script type="text/javascript">
function MoveCursorToTheEnd(input)
{
var position = input.value.length;

if (/gecko/i.test(navigator.userAgent))
{
input.setSelectionRange(position, position);
}
else
{
var textRange = input.createTextRange();
textRange.collapse(true);
textRange.moveStart("character", position);
textRange.moveEnd("character", 0);
textRange.select();
}
}
</script>

--end code --
 

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

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top