For Programmers: Free Programming Magazines  


Home > Archive > ASP .NET > December 2006 > Edit function on Datagrid









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Edit function on Datagrid
Blasting Cap

2006-12-21, 7:07 pm

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
bruce barker

2006-12-21, 7:07 pm

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

-- bruce (sqlwork.com)

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

Milosz Skalecki

2006-12-21, 10:06 pm

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 --



--
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
>

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2010 codecomments.com