Javascript 如何在ASP.NET数据网格中使用Jquery附加到drowdownlist?

Javascript 如何在ASP.NET数据网格中使用Jquery附加到drowdownlist?,javascript,jquery,asp.net,xml,Javascript,Jquery,Asp.net,Xml,我的“aspx”页面中的以下函数正在运行,但GridControl中的“下拉菜单”正在被复制。。。从原始行。未从附加行更改它。你可以看到我尝试的路线,但我不确定该放什么。我还发布了网格控件本身。我认为您不需要webmethod,也不需要任何代码。一个脚本天才应该能够告诉我我需要什么,我相信。 仅供参考。。。这是使用aspsnippits.com的按需加载-至少是其中的一个概念 //Function to receive XML response append rows to GridView

我的“aspx”页面中的以下函数正在运行,但GridControl中的“下拉菜单”正在被复制。。。从原始行。未从附加行更改它。你可以看到我尝试的路线,但我不确定该放什么。我还发布了网格控件本身。我认为您不需要webmethod,也不需要任何代码。一个脚本天才应该能够告诉我我需要什么,我相信。 仅供参考。。。这是使用aspsnippits.com的按需加载-至少是其中的一个概念

 //Function to receive XML response append rows to GridView
function OnSuccess(response) {
    var xmlDoc = $.parseXML(response.d);
    var xml = $(xmlDoc);
    pageCount = parseInt(xml.find("PageCount").eq(0).find("PageCount").text());
    var customers = xml.find("Customers");
    $("[id$=GridView_MyCustomers] .loader").remove();
    customers.each(function () {
        var customer = $(this);
        var row = $("[id$=GridView_MyCustomers] tr").eq(0).clone(true);
        $(".ID", row).html(customer.find("id").text());
        $(".Name", row).html(customer.find("customername").text());
        $(".company", row).html(customer.find("company").text());
        $(".email", row).html(customer.find("email").text());
        $(".phone", row).html(customer.find("phone").text());
        $(".address", row).html(customer.find("customeraddress").text());

        $(".projeng", row).val(customer.find("usproengineer").text()).change(); //does not work

        $(".regdate", row).html(customer.find("registrationdate").text());
        $(".payterms", row).html(customer.find("paymentterms").text());
        $(".country", row).html(customer.find("country").text());
        $("[id$=GridView_MyCustomers]").append(row);
    });

    //Hide Loader
    $("#loader").hide();
}

 <%--My Customers«e¥x¬É­±--%>
 <div id="customers" runat="server" style="padding-left:10px"> 
     <h2>My Customers</h2>
     <img src="Images/raise.png" alt="" id="jqshow_8" />
     <img src="Images/drop.png" alt="" id="jqhide_8" />
     <asp:LinkButton ID="jqlbtn_8" runat="server" OnClick="lbtn_MyCustomers_Click" CssClass="linkbutton-customer"
         >My Customers</asp:LinkButton>            
     &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
     <span id="tag_8">
        <asp:Button ID="export_customer" runat="server" Width="150px" Height="25px"
            Text="Export Customer List" onclick="export_customer_Click" />
     </span>
     <input id="hidden_8" type="hidden" runat="server" value="0" /> &nbsp;&nbsp;&nbsp;
     <asp:Button ID="btPrev" runat="server" Text="&lt;-" />
     <asp:Button ID="btNext" runat="server" Text="-&gt;" onclick="btNext_Click" />
     <div id="div_8">
     <div id="dvGrid" style="max-height:500px; width:auto; overflow-y:auto">
     <asp:GridView ID="GridView_MyCustomers" runat="server" AllowSorting="true"  OnSorting="Customer_Sorting"
        AutoGenerateColumns="False" CssClass="GridViewStyle" 
        onrowdatabound="GridView_MyCustomers_RowDataBound" DataKeyNames="usproengineer" OnPageIndexChanging="GridView_MyCustomers_PageIndexChanging"
        onrowdeleting="lbtn_CustomerDelete" 
              PageSize="500" >        
      <Columns>
        <asp:BoundField HeaderText="ID" DataField="id" ItemStyle-CssClass="ID" />       
        <asp:BoundField HeaderText="Contact" DataField="customername"  SortExpression="customername" ItemStyle-CssClass="Name" />
        <asp:BoundField HeaderText="Company" DataField="company"  SortExpression="company" ItemStyle-CssClass="company" />
        <asp:templateField HeaderText="Email" SortExpression="Email" ItemStyle-CssClass="email">
            <ItemTemplate>
                <asp:LinkButton ID="lbtn_customeremail" runat="server" OnClick="lbtn_customeremail_Click" Text='<%#Eval("email") %>' 
                   ></asp:LinkButton>
            </ItemTemplate>
        </asp:templateField>
        <asp:BoundField HeaderText="Phone" DataField="phone" ItemStyle-CssClass="phone"/>
        <asp:BoundField HeaderText="Address" DataField="customeraddress" ItemStyle-CssClass="address"
              ItemStyle-Width="150px" >
            <ItemStyle Width="150px"></ItemStyle>
          </asp:BoundField>
        <asp:templateField HeaderText="US Project Manager" ItemStyle-CssClass="projeng">
            <ItemTemplate>
                <asp:DropDownList ID="ddl_customerproeng" runat="server" OnSelectedIndexChanged="customerproeng_SelectedIndexChanged"
                     AutoPostBack="true">
                </asp:DropDownList>
            </ItemTemplate>
        </asp:templateField>
        <asp:BoundField HeaderText="Registration Date" DataField="registrationdate" ItemStyle-CssClass="regdate"/>
        <asp:BoundField HeaderText="Note" DataField="paymentterms" ItemStyle-CssClass="payterms"
              ItemStyle-Width="150px" >
                <ItemStyle Width="150px"></ItemStyle>
          </asp:BoundField>
        <asp:TemplateField HeaderText="Delete">
            <ItemTemplate>
                <asp:LinkButton ID="lbtn_customerdelete" runat="server" CommandName="Delete" OnClientClick="{if(confirm('Are you sure to delete this customer?')){ return true;}return false;}" Text="Delete"></asp:LinkButton>
            </ItemTemplate>
       </asp:TemplateField>
       <asp:TemplateField Visible="false" HeaderText="?吼country" ItemStyle-CssClass="country">
            <ItemTemplate>
                <asp:Label runat="server" ID="lbl_country" ReadOnly="True" Text='<%#Eval("country") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>        
    <RowStyle CssClass="RowStyle" />
    <FooterStyle CssClass="FooterStyle" />
    <PagerStyle CssClass="PagerStyle" HorizontalAlign="Center" />
    <SelectedRowStyle CssClass="SelectedRowStyle" />
    <HeaderStyle CssClass="HeaderStyle" />
    <EditRowStyle CssClass="EditRowStyle" />
    <AlternatingRowStyle CssClass="AltRowStyle" />
 </asp:GridView>
 </div>
 </div>          

我应该在我的调试和调试中添加:。我可以在DOM中看到值的变化,看起来行的单元格确实有正确的值,该值被附加到网格中。但是它仍然没有显示在屏幕上,并且在最后的下拉列表中仍然显示选择了错误的人。

您的班级$.projeng。。。不在下拉列表上,它在模板上。首先尝试将类移动到ddl

要通过文本选择下拉项,可以尝试以下操作:

$("#ddl_customerproeng option").filter(function() {
    return ($(this).text() == "the text"); // does current option's text = "the text"?
}).prop("selected", true); // select the option.

你的班级$.projeng。。。不在下拉列表上,它在模板上。首先尝试将类移动到ddl。那你想做什么?更改ddl中的选定项?就是这样…但是,我可以让它工作:$.projeng,row.val'35';,但不按文本选择。除非有一个我看不到的属性。无论如何,我将ID添加到数据流中,它就可以工作了。如果您愿意,您可以提交以下答案。谢谢。补充答案,如果你需要的话,再加上一些额外的。