English 中文(简体)
Grid Inline editing with JavaScript, weird behaviour
原标题:

I made this invoice page. There is a repeater that generates a table. There are invoice item descriptions coming into td tags encapsulated with div tags like this:

<asp:Repeater ID="Repeater1" runat="server">
           <ItemTemplate> 
            <tr>
             <td class="griditem text">
                 <div class="invoiceDescription" id= <%# "item-" + Eval("ID") %>  value= <%# Eval("ID") %>  onclick="InvoiceItemClicked(this);">
                    <%# Eval("Description") %>
                 </div>
             </td>
             <td class="gridnumb text r">
             <%# String.Format("{0:n}", Eval("Quantity"))%>
             </td>
             <td class="gridnumb text r">
             <%# String.Format("{0:c}", Eval("UnitCost"))%>
             </td>
             <td class="gridnumb text r">
             <%# String.Format("{0:c}", Eval("Total"))%>
             </td>
            </tr>
           </ItemTemplate>
          </asp:Repeater>

If you see the first line, I call a javascript onclick. The function is like this (uses jQuery):

function InvoiceItemClicked(elm) {
        var textbox = document.createElement( input );
        textbox.setAttribute( type ,  text );
        textbox.value = $(elm).text();
        $(elm).html(textbox);
    }

This is the first time I try to do sth like this, and it worked in the first shot. It transforms lines into textboxes with same text set into them. But the problem is when the generated textbox is clicked (focus), the text inside it disappears.

I will also appreciate any other best practices to do this inline editing. I need to then update the items via webservices etc..

Thanks in advance.

问题回答

yep my bad!

function InvoiceItemClicked(elm) {
        var b = $(elm).hasClass( invoiceDescriptionEditing );
        if(!b)
        {
            var textbox = document.createElement( input );
            textbox.setAttribute( type ,  text );
            textbox.setAttribute( id ,  txt );
            $(textbox).css( width ,  550px );
            textbox.value = $(elm).text();
            $(elm).html(textbox);

            $(elm).removeClass( invoiceDescriptionEditable );
            $(elm).addClass( invoiceDescriptionEditing );
        }

    }

this is aight! :)





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签