Re: Setting id in a dynmaically generated checkboxlist

From: Eirik Eldorsen (eirik_at_NO__SPAM__eldorsens.nettsider.no)
Date: 11/15/04


Date: Mon, 15 Nov 2004 23:58:15 +0100

Thank you so much for the help :-D

It was a stupid bug. I forgot the where clause in my select statment :-)

"SELECT * " +
"FROM Elementes " +
"WHERE CategoriID = " + id +

"Scott Allen" <bitmask@[nospam].fred.net> wrote in message
news:p9bip0pl64deh56qm59lc96qpmu9eck2g6@4ax.com...
> >
>>For each listitem in the repeater I want write out Title, Explenation, and
>>a
>>checkboxlist containing the elementtext's. If i use a static name on the
>>checkboxlistid, every checkboxlist get all the elements. This is not what
>>I
>>want. I could use a hidde nfield to contain the id, but I still need a
>>uniqe
>>name for eah checkboxlist.
>>
>
> That's interesting - the ID of the control should not change the
> databinding behavior in any way. Here is an example (apologies for any
> wierd line breaks):
>
> <form id="Form1" method="post" runat="server">
> <table>
> <asp:Repeater ID="Repeater1" Runat="server">
> <ItemTemplate>
> <tr>
> <td><%# DataBinder.Eval(Container.DataItem, "Title") %></td>
> <td><%# DataBinder.Eval(Container.DataItem, "Explanation")
> %></td>
> <td>
> <asp:CheckBoxList ID="CheckBoxList1" Runat="server"
> DataSource='<%#DataBinder.Eval(Container.DataItem, "Elements")
> %>'
> DataTextField="Name">
> </asp:CheckBoxList>
> </td>
> </tr>
> </ItemTemplate>
> </asp:Repeater>
> </table>
> </form>
>
>
> The code behind this form is:
>
> using System;
> using System.Collections;
> using System.ComponentModel;
> using System.Data;
> using System.Drawing;
> using System.Web;
> using System.Web.SessionState;
> using System.Web.UI;
> using System.Web.UI.WebControls;
> using System.Web.UI.HtmlControls;
>
> namespace aspnet.repeaters
> {
> public class checkboxlist : System.Web.UI.Page
> {
> protected Repeater Repeater1;
>
> private void Page_Load(object sender, System.EventArgs e)
> {
> if(!Page.IsPostBack)
> {
> Category[] categories = GetCategories();
> Repeater1.DataSource = categories;
> Repeater1.DataBind();
> }
> }
>
> private Category[] GetCategories()
> {
> Category[] categories = new Category[3];
>
> for(int i = 0; i < categories.Length; i++)
> {
> categories[i] = GetCategory(i);
> }
>
> return categories;
> }
>
> private Category GetCategory(int i)
> {
> string title = i.ToString() + "CatTitle";
> string ex = i.ToString() + "Explanation";
> Element[] elements = GetElements(i);
>
> return new Category(title, ex, elements);
> }
>
> private Element[] GetElements(int i)
> {
> Element[] elements = new Element[i + 2];
>
> for(int j = 0; j < elements.Length; j++)
> {
> elements[j] = new Element(i.ToString() + j.ToString()
> + "Element");
> }
>
> return elements;
> }
>
> #region Web Form Designer generated code
> override protected void OnInit(EventArgs e)
> {
> InitializeComponent();
> base.OnInit(e);
> }
>
> private void InitializeComponent()
> {
> this.Load += new System.EventHandler(this.Page_Load);
> }
> #endregion
> }
>
> class Category
> {
> public Category(string title, string explanation,
> Element[] elements)
> {
> this.title = title;
> this.explanation = explanation;
> this.elements = elements;
> }
>
> public string Title
> {
> get { return title; }
> }
>
> public string Explanation
> {
> get { return explanation; }
> }
>
> public Element[] Elements
> {
> get { return elements; }
> }
>
> private string title;
> private string explanation;
> private Element[] elements;
> }
>
> class Element
> {
> public Element(string name)
> {
> this.name = name;
> }
>
> public string Name
> {
> get { return name; }
> }
>
> private string name;
> }
> }
>
>
> What I'll get is a Repeater with three rows. Each row has a
> CheckBoxList with different elements displayed (and they all have
> unique client IDs).
>
> --
> Scott
> http://www.OdeToCode.com/blogs/scott/



Relevant Pages

  • Re: variable length fields for flexibility in subroutines
    ... private string _IntBlock; ... public string IBreturn ... public string IBstreet ...
    (comp.lang.cobol)
  • Re: Threading with an object and Session
    ... thread post the mail body directly to the session, ... private string _DatabaseConnection; ... public string EmailNameField ...
    (microsoft.public.dotnet.framework.aspnet)
  • Default.aspx.cs
    ... string strReturn = SendInvitations(txtName.Text, ... private string SendInvitations(string name, string body, string ... emails, string codedString, ArrayList friend) ... public string subject ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Arraylist.remove problem?? Please help.
    ... static string group; ... private string numb; ... private int messageNumber; ... public string Subject ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Reflection in 1.1 and 2.0 - generic, fast copy delegate?
    ... Your delegate solution is is still significantly more efficient that reflection. ... Also you need permissions to emit code with the LCG version whereas using delegates does not appear to require permissions beyond those for public reflection and so you can have a fast solution even in low trust environments. ... private string _firstName; ...
    (microsoft.public.dotnet.framework.clr)