简体   繁体   English

对于ItemTemplate的ASP DropDownList,服务器标签格式不正确

[英]Server tag not well formed for ASP DropDownList for ItemTemplate

<asp:TemplateField HeaderText="Company Membership">
    <ItemTemplate>
        <asp:DropDownList id="ddlCompanyMembership" runat="server" class="form-control" onchange="verifyUser('<%# ((DataRowView)Container.DataItem)["CCMP_CODE"].ToString() %>');" />
    </ItemTemplate>
</asp:TemplateField>

I can't seem to build this properly. 我似乎无法正确构建它。 It's suppose to call a Javascript function and pass the value to the function. 假设调用Javascript函数并将值传递给该函数。 But it shows Server tag not well formed error. 但是它表明Server tag not well formed错误。

I've tried looking for solutions, some said the quotes and double quotes do matter. 我试图寻找解决方案,有人说引号和双引号确实很重要。 But I've tried everything and nothing's working. 但是我已经尝试了一切,但没有任何效果。

You may consider binding onchange event on the server side by handling GridView's RowDataBound event. 您可以考虑通过处理GridView的RowDataBound事件在服务器端绑定onchange事件。 You will be able to bind your event as follows which is more convenient in my opinion. 您将可以按以下方式绑定事件,我认为这更加方便。

void CustomersGridView_RowDataBound(Object sender, GridViewRowEventArgs e) 
{
   if (e.Row.RowType == DataControlRowType.DataRow) 
   {
       // Find your drop down list
       DropDownList ddl = (DropDownList)e.Row.FindControl("ddlCompanyMembership");

       // Add onchange event as attribute
       ddl.Attributes["onchange"] = "verifyUser('your logic');";
   }
}
onchange="verifyUser('<%# DataBinder.Eval(Container.DataItem, "CCMP_CODE").ToString()%>');"

上面的代码可帮助您使其正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM