DataList ItemCommand using Placeholder Ctrl

Discussion in 'ASP .Net' started by Stuart Shay, May 20, 2008.

  1. Stuart Shay

    Stuart Shay Guest

    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

    http://www.codeguru.com/csharp/.net/net_asp/controls/article.php/c12495/

    void rptFields_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
    if (e.Item.ItemType != ListItemType.Item && e.Item.ItemType
    != ListItemType.AlternatingItem)
    return;

    DataRow dr = ((DataRowView)e.Item.DataItem).Row;
    PlaceHolder pl = (PlaceHolder)e.Item.FindControl("plControl");
    switch (dr["DataType"].ToString().ToLower())
    {
    case "string":
    TextBox txt = new TextBox();
    txt.ID = "txtField" + dr["pkParameterID"].ToString();
    pl.Controls.Add(txt);
    break;

    case "tf":
    CheckBox chk = new CheckBox();
    chk.ID = "chkField" + dr["pkParameterID"].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
     
    Stuart Shay, May 20, 2008
    #1
    1. Advertising

  2. 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]
    http://msmvps.com/blogs/egoldin
    http://usableasp.net


    "Stuart Shay" <> wrote in message
    news:...
    > 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
    >
    > http://www.codeguru.com/csharp/.net/net_asp/controls/article.php/c12495/
    >
    > void rptFields_ItemDataBound(object sender, RepeaterItemEventArgs e)
    > {
    > if (e.Item.ItemType != ListItemType.Item && e.Item.ItemType
    > != ListItemType.AlternatingItem)
    > return;
    >
    > DataRow dr = ((DataRowView)e.Item.DataItem).Row;
    > PlaceHolder pl = (PlaceHolder)e.Item.FindControl("plControl");
    > switch (dr["DataType"].ToString().ToLower())
    > {
    > case "string":
    > TextBox txt = new TextBox();
    > txt.ID = "txtField" + dr["pkParameterID"].ToString();
    > pl.Controls.Add(txt);
    > break;
    >
    > case "tf":
    > CheckBox chk = new CheckBox();
    > chk.ID = "chkField" + dr["pkParameterID"].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, May 20, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Danny

    Implement Ctrl-C, Ctrl-V

    Danny, Aug 14, 2003, in forum: C++
    Replies:
    5
    Views:
    673
    CBFalconer
    Aug 15, 2003
  2. Danny

    Implement Ctrl-C, Ctrl-V

    Danny, Aug 14, 2003, in forum: C Programming
    Replies:
    5
    Views:
    692
    CBFalconer
    Aug 15, 2003
  3. Angus
    Replies:
    5
    Views:
    2,237
    Michael Rauscher
    Nov 18, 2006
  4. Replies:
    2
    Views:
    1,452
    Munna
    Jul 10, 2008
  5. Replies:
    0
    Views:
    588
Loading...

Share This Page