服务器标记的格式不正确。(的DataBinder.Eval) [英] The server tag is not well formed.(databinder.eval)

查看:356
本文介绍了服务器标记的格式不正确。(的DataBinder.Eval)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想工作,则下列code。

I am trying to working the following code.

 <asp:DataGrid ID="Grid" runat="server"  DataKeyField="KeyID" CssClass="grid"
...
<asp:CheckBox runat="server"  ID="checkBox-<%#DataBinder.Eval(Container.DataItem,"KeyID")%>" AutoPostBack="false"></asp:CheckBox>

当我运行code,我有以下错误:

When I run the code,I have got the below error:

Error   25  The server tag is not well formed.

请注意:这是工作无=服务器。
什么是这个问题的补救措施?

Note : This is working without runat="server". What is the remedy for this problem ?

推荐答案

您并不需要设置CheckBox的ID,做你想做的事情(改变背景颜色)的东西。您的复选框应该像这样(我添加了的KeyID 作为文本值,如果要显示它...或者你可以删除,如果你只想要该复选框)

You don't need to set the ID of the CheckBox to do what you want to do (change the background color). Your CheckBox should look like this (I added the KeyID as the text value if you want to display it... or you can just remove that if you only want the checkbox):

<asp:CheckBox runat="server" ID="checkbox" Text='<%# Eval("KeyID") %>' AutoPostBack="false"></asp:CheckBox>  

现在您的复选框会呈现这样的事情:

Now your checkbox will render something like this:

<input id="MainContent_Grid_checkbox_0" type="checkbox" name="ctl00$MainContent$Grid$ctl02$checkbox" /><label for="MainContent_Grid_checkbox_0">Value of KeyID</label> 

由于所有的名称以复选框结尾,你可以在更改事件应用功能,其名称为复选框结尾的元素。您没有指定,这是一个JavaScript的问题,或者如果你正在使用jQuery ......这个答案使用 jQuery的

<script>
    $('input[name$="checkbox"]').change(function () {
        if ($(this).is(':checked')) {
            $(this).parent().css('background-color', 'yellow');
        }
        else {
            $(this).parent().css('background-color', 'white');
        }
    });
</script> 

这将确定复选框被选中,如果是这样,将设置其母公司的背景颜色(&LT; TD&GT; ,它在,里面呈现的HTML DataGrid中),根据不同的值。

That will determine if the checkbox is checked, and if so it will set the background-color of its parent (the <td> that it is in, inside the DataGrid rendered HTML), depending on the value.

同样的,你可以去到下一个父()并突出显示整行。

Likewise, you can go up to the next parent() and highlight the entire row.

资源:
jquery选择

<一个href=\"http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.checkbox.oncheckedchanged%28v=vs.110%29.aspx\"相对=nofollow> OnCheckedChanged - 你会在code工艺落后的情况下,在JavaScript

OnCheckedChanged -- an event that you would process in the code behind, not in JavaScript.

这篇关于服务器标记的格式不正确。(的DataBinder.Eval)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆