如何将具有数据源的转发器控件内的Checklistbox绑定为LINQ

时间:2010-08-23 12:12:13

标签: asp.net linq

我的网站我正在使用Repeater控件,它还包含checkboxlist控件。

现在我的问题是我已成功在转发器控件中绑定“参数类型”,但是当我绑定复选框值时,它不会出现在显示中

<asp:Repeater ID="Repeater1" runat="server">
            <ItemTemplate>
                <h4>
                    <%#Container.DataItem%></h4>
                <asp:CheckBoxList ID="chkParList" runat="server" RepeatDirection="Horizontal" 
                DataTextField = >
                </asp:CheckBoxList>
                <br /><br />
            </ItemTemplate>
            <SeparatorTemplate>
                <hr />
            </SeparatorTemplate>
        </asp:Repeater>

以下* .cs文件是我的代码

IMonitoringDataInfo objMonitoringDataInfo = new ChannelFactory<IMonitoringDataInfo>("MonitoringDataInfo").CreateChannel();
                Collection<ParameterDetailDTO> clParameterDetailDTO = objMonitoringDataInfo.GetAllParameters(idList, out errorCode);

                var parameters = (from resx in clParameterDetailDTO
                                  select resx.ParameterType).Distinct();

                Repeater1.DataSource = parameters.ToList();
                Repeater1.DataBind();
                counter = Repeater1.Items.Count;
                while (i < counter - 1)
                {
                    foreach (var parType in parameters)
                    {

                    var items = from resx in clParameterDetailDTO
                                where resx.ParameterType.ToLower().Contains(parType.ToLower())
                                select new { resx.ParameterName, resx.ParameterID };  

                        ((CheckBoxList)(Repeater1.Items[i].FindControl("chkParList"))).DataSource = items;
                        ((CheckBoxList)(Repeater1.Items[i].FindControl("chkParList"))).DataTextField = "ParameterName";
                        ((CheckBoxList)(Repeater1.Items[i].FindControl("chkParList"))).DataValueField = "ParameterID";
                        ((CheckBoxList)(Repeater1.Items[i].FindControl("chkParList"))).DataBind();


                    }
                    i++;
                }

我使用LINQ作为数据源

请帮帮忙?

2 个答案:

答案 0 :(得分:0)

将OnItemDataBound事件添加到Repeater:

<div id="root"></div>
<script crossorigin src="https://unpkg.com/react@16/umd/react.development.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
<script crossorigin src="https://unpkg.com/prop-types@15.6.2/prop-types.js"></script>
<script crossorigin src="https://unpkg.com/babel-standalone@6.26.0/babel.min.js"></script>
<script type="text/babel">

    function SayHello(props) {
        return (
            <div>
                Hello {props.firstName} {props.lastName}!
            </div>
        )
    }

    SayHello.propTypes = {
        firstName: PropTypes.string.isRequired,
        lastName: PropTypes.string.isRequired,
    }

    ReactDOM.render(<SayHello />, document.getElementById('root'))

</script>

然后在后面的代码中执行以下操作:

<asp:Repeater ID="Repeater1" OnItemDataBound="Repeater1_ItemDataBound" runat="server">

答案 1 :(得分:-1)

尝试将CheckBoxList绑定放在转发器的ItemDataBound事件中。

请参阅:

Repeater.ItemDataBound Event

Using OnItemDataBound with Repeater in ASP.NET and C#