Open New Window from DataList Item...

Discussion in 'ASP .Net' started by =?Utf-8?B?SnVsZXNfQW5pbWU=?=, Nov 22, 2005.

  1. Is it possible to create an onclick event which is attached to individual
    datalist items?

    I have a Datalist with some details on employees, and when you click on one
    we would like to open a new window which will be populated with some more
    data on this employee.

    The closest I have come is populating the
    DataList.Attributes.Add("onclick","sUrl") with some information but when I
    run the code it needs two clicks to open a window, and on the second click
    opens the previous employee details...

    DataList with two employees: -

    Emp1, Emp2

    Click on Emp1 - nothing happens although the Attribute is added to the
    DataList. On second click I select Emp2 and the app shows details of Emp1.

    Help is required...
     
    =?Utf-8?B?SnVsZXNfQW5pbWU=?=, Nov 22, 2005
    #1
    1. Advertising

  2. =?Utf-8?B?SnVsZXNfQW5pbWU=?=

    Mr Newbie Guest

    You have two options. You can either force the single click to be client
    side which means an event which performs some javascript action or to make
    the list autopostback true and force the index changed event to fire, now
    you need to get the required action on postback. You could write an onLoad
    event for the page when its loaded and open a child window this way.

    --
    Best Regards

    The Inimitable Mr Newbie º¿º


    "Jules_Anime" <> wrote in message
    news:D...
    > Is it possible to create an onclick event which is attached to individual
    > datalist items?
    >
    > I have a Datalist with some details on employees, and when you click on
    > one
    > we would like to open a new window which will be populated with some more
    > data on this employee.
    >
    > The closest I have come is populating the
    > DataList.Attributes.Add("onclick","sUrl") with some information but when I
    > run the code it needs two clicks to open a window, and on the second click
    > opens the previous employee details...
    >
    > DataList with two employees: -
    >
    > Emp1, Emp2
    >
    > Click on Emp1 - nothing happens although the Attribute is added to the
    > DataList. On second click I select Emp2 and the app shows details of Emp1.
    >
    > Help is required...
     
    Mr Newbie, Nov 22, 2005
    #2
    1. Advertising

  3. Had a play and managed to get is working okay...although there is a page
    refresh which I am going to have to correct.

    I added the Response.Write to my on Command call....

    private void AddList_ItemCommand(object source,
    System.Web.UI.WebControls.DataListCommandEventArgs e)
    {
    if (e.CommandName == "DETAIL")
    {
    AddList.SelectedIndex = e.Item.ItemIndex;
    Label2.Text =
    ((Label)AddList.SelectedItem.FindControl("Label1")).Text.ToString();
    //Server.Transfer ( "StaffDetails.aspx" );
    StringBuilder url = new StringBuilder ( );
    url.Append ( "StaffDetails.aspx?" );
    url.Append ( "&Name=" );
    url.Append ( Server.UrlEncode ( Label2.Text ) );
    //OpenPopUp(AddList.SelectedItem, url.ToString());
    Response.Write("<script language=Javascript>window.open('" + url.ToString()
    + "','StaffDetails', 'width=600, height=200');</script>");
    }
    }

    If anyone has a better solution I would be interested to know.
    "Jules_Anime" wrote:

    > Is it possible to create an onclick event which is attached to individual
    > datalist items?
    >
    > I have a Datalist with some details on employees, and when you click on one
    > we would like to open a new window which will be populated with some more
    > data on this employee.
    >
    > The closest I have come is populating the
    > DataList.Attributes.Add("onclick","sUrl") with some information but when I
    > run the code it needs two clicks to open a window, and on the second click
    > opens the previous employee details...
    >
    > DataList with two employees: -
    >
    > Emp1, Emp2
    >
    > Click on Emp1 - nothing happens although the Attribute is added to the
    > DataList. On second click I select Emp2 and the app shows details of Emp1.
    >
    > Help is required...
     
    =?Utf-8?B?SnVsZXNfQW5pbWU=?=, Nov 22, 2005
    #3
    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. Nevyn Twyll
    Replies:
    1
    Views:
    7,503
    S. Justin Gengo
    Aug 16, 2003
  2. Nevyn Twyll
    Replies:
    1
    Views:
    234
    S. Justin Gengo
    Aug 16, 2003
  3. Ann
    Replies:
    0
    Views:
    154
  4. Gordon
    Replies:
    3
    Views:
    310
    Steven Burn
    Apr 16, 2004
  5. PC HUA
    Replies:
    2
    Views:
    422
    PC HUA
    May 19, 2004
Loading...

Share This Page