1

I have these checkbox on a Repeater:

<asp:Repeater id="repeaterCategories" runat="server">
    <ItemTemplate>
        ...

        <asp:CheckBox ID="chbCategoria" Text="My Label" runat="server" />

        ...
    </ItemTemplate>
</asp:Repeater>

every checkbox must coincide with a Page ID taken from Database (every repeaterCategories Item has its unique id, so that one).

How can I set it? So, at the postback, I check which CheckBox Controls are Checked and I get the IDs.

4

2 に答える 2

2

このようなカスタム属性を追加してみてください

protected void repeaterCategories_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
    {
        CheckBox chk = e.Item.FindControl("chbCategoria") as CheckBox ;
        chk.Attributes.Add("PageID", DataBinder.Eval(e.Item.DataItem, "DB_FIELD").ToString());
    }
}
于 2013-04-23T13:59:28.970 に答える
0

ユーザー制御ページ:

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="WebUserControl.ascx.cs" Inherits="WebUserControl" %>
<asp:CheckBox id ="MyCheckBox" runat="server"/>

コードビハインド:

using System;

public partial class WebUserControl : System.Web.UI.UserControl
{
    private string _myProperty;
    public string MyProperty 
    {
        get { return this._myProperty; }
        set { this._myProperty = value; }
    }

    public bool IsChecked
    {
        get 
        {
            return this.MyCheckBox.Checked;
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {

    }
}

リピーターページで:

<%@ Register Src="~/WebUserControl.ascx" TagPrefix="uc1" TagName="WebUserControl" %>

リピーター内部:

<asp:Repeater id="repeaterCategories" runat="server">
    <ItemTemplate>
        ...

        <uc1:WebUserControl runat="server" ID="WebUserControl" MyProperty="My_ID_Value" />

        ...
    </ItemTemplate>
</asp:Repeater>

Web ユーザー コントロールには、好きなだけプロパティを追加できます。

于 2013-04-23T13:49:29.057 に答える