DataList ItemCommand - trying to get data from contained control

Discussion in 'ASP .Net Web Controls' started by Xavier Pacheco, Aug 24, 2005.

  1. Can anyone make heads or tails out of this? I have a DataList control
    that contains a DropDownList and a HyperLink control. The HyperLink
    control initiates a command named "REGISTER".

    The following code executes, I find the DropDownList, but it contains
    no values. IOW, it appears to be empty.

    Am I going about this correctly? When the user presses the hyperlink
    contained in the ItemTemplate of the DataList, I want to get the
    selected value of the DropDownList, also contained in the Item Template
    of the DataList.

    private void DataList1_ItemCommand(object source,
    system.Web.UI.WebControls.DataListCommandEventArgs e)
    {
    if ( e.CommandName == "REGISTER" )
    {
    string ctl_name = String.Format( CTRLNAME, e.Item.ItemIndex );
    DropDownList ddl = (DropDownList)e.Item.FindControl(
    "DropDownList1" );
    int EventInstanceID = Int32.Parse( ddl.SelectedValue );
    }
    }

    Any ideas ?
    - x
    Xavier Pacheco, Aug 24, 2005
    #1
    1. Advertising

  2. It looks like you are accessing the control correctly, but before I try to
    solve your problem any further, might I point out that you are assigning
    values from that control to variables, but then the eventhandler is done. In
    otherwords, can I ask how you are determining whether or not you actually
    got the data from the control?
    --
    Nathan Sokalski

    http://www.nathansokalski.com/

    "Xavier Pacheco" <> wrote in message
    news:...
    > Can anyone make heads or tails out of this? I have a DataList control
    > that contains a DropDownList and a HyperLink control. The HyperLink
    > control initiates a command named "REGISTER".
    >
    > The following code executes, I find the DropDownList, but it contains
    > no values. IOW, it appears to be empty.
    >
    > Am I going about this correctly? When the user presses the hyperlink
    > contained in the ItemTemplate of the DataList, I want to get the
    > selected value of the DropDownList, also contained in the Item Template
    > of the DataList.
    >
    > private void DataList1_ItemCommand(object source,
    > system.Web.UI.WebControls.DataListCommandEventArgs e)
    > {
    > if ( e.CommandName == "REGISTER" )
    > {
    > string ctl_name = String.Format( CTRLNAME, e.Item.ItemIndex );
    > DropDownList ddl = (DropDownList)e.Item.FindControl(
    > "DropDownList1" );
    > int EventInstanceID = Int32.Parse( ddl.SelectedValue );
    > }
    > }
    >
    > Any ideas ?
    > - x
    Nathan Sokalski, Aug 27, 2005
    #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. Kenneth

    Itemcommand and Datalist problem

    Kenneth, Jan 3, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    1,938
    Natty Gur
    Jan 5, 2004
  2. Marina
    Replies:
    3
    Views:
    2,778
    Chad Crowder
    Feb 29, 2004
  3. Nevyn Twyll
    Replies:
    8
    Views:
    1,867
  4. Replies:
    1
    Views:
    4,516
    Teemu Keiski
    Jul 24, 2006
  5. Ryan Shaw

    Custom Server Control with DataList and ItemCommand not firing

    Ryan Shaw, Jun 1, 2005, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    158
    Sergey Polyakov
    Jun 1, 2005
Loading...

Share This Page