DataList ItemCommand using Placeholder Ctrl

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Stuart Shay

    DataList ItemCommand using Placeholder Ctrl

    Hello All:

    I have a Datalist where each row has TextBoxes and Dropdowns that are
    created dynamically. The code renders correctly and is very similar to this
    sample I found



    void rptFields_ItemD ataBound(object sender, RepeaterItemEve ntArgs e)
    {
    if (e.Item.ItemTyp e != ListItemType.It em && e.Item.ItemType
    != ListItemType.Al ternatingItem)
    return;

    DataRow dr = ((DataRowView)e .Item.DataItem) .Row;
    PlaceHolder pl = (PlaceHolder)e. Item.FindContro l("plControl" );
    switch (dr["DataType"].ToString().ToL ower())
    {
    case "string":
    TextBox txt = new TextBox();
    txt.ID = "txtField" + dr["pkParamete rID"].ToString();
    pl.Controls.Add (txt);
    break;

    case "tf":
    CheckBox chk = new CheckBox();
    chk.ID = "chkField" + dr["pkParamete rID"].ToString();
    pl.Controls.Add (chk);
    break;
    }


    When I call the DataList ItemCommand Event, I am unable to reference the
    dropdown list or textbox by using the FindControl Method even if I hardcode
    the ControlId as a test.

    How can I get the selected value or text of the control

    Any help appreciated

    Thanks
    Stuart

  • Eliyahu Goldin

    #2
    Re: DataList ItemCommand using Placeholder Ctrl

    You are referring to ItemCommand event. Note, that DataItem is available
    only in ItemDataBound event. This is the only point where the control meets
    its datasource.

    --
    Eliyahu Goldin,
    Software Developer
    Microsoft MVP [ASP.NET]




    "Stuart Shay" <sshay@yahoo.co mwrote in message
    news:54607667-03CA-4055-8284-098CCDC9328D@mi crosoft.com...
    Hello All:
    >
    I have a Datalist where each row has TextBoxes and Dropdowns that are
    created dynamically. The code renders correctly and is very similar to
    this sample I found
    >

    >
    void rptFields_ItemD ataBound(object sender, RepeaterItemEve ntArgs e)
    {
    if (e.Item.ItemTyp e != ListItemType.It em && e.Item.ItemType
    != ListItemType.Al ternatingItem)
    return;
    >
    DataRow dr = ((DataRowView)e .Item.DataItem) .Row;
    PlaceHolder pl = (PlaceHolder)e. Item.FindContro l("plControl" );
    switch (dr["DataType"].ToString().ToL ower())
    {
    case "string":
    TextBox txt = new TextBox();
    txt.ID = "txtField" + dr["pkParamete rID"].ToString();
    pl.Controls.Add (txt);
    break;
    >
    case "tf":
    CheckBox chk = new CheckBox();
    chk.ID = "chkField" + dr["pkParamete rID"].ToString();
    pl.Controls.Add (chk);
    break;
    }
    >
    >
    When I call the DataList ItemCommand Event, I am unable to reference the
    dropdown list or textbox by using the FindControl Method even if I
    hardcode the ControlId as a test.
    >
    How can I get the selected value or text of the control
    >
    Any help appreciated
    >
    Thanks
    Stuart

    Comment

    Working...