Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   Open New Window from DataList Item... (http://www.velocityreviews.com/forums/t114073-open-new-window-from-datalist-item.html)

=?Utf-8?B?SnVsZXNfQW5pbWU=?= 11-22-2005 11:48 AM

Open New Window from DataList Item...
 
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 11-22-2005 11:57 AM

Re: Open New Window from DataList Item...
 
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" <JulesAnime@discussions.microsoft.com> wrote in message
news:DC6F1519-8C82-4E46-BDB5-435228E7D01B@microsoft.com...
> 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=?= 11-22-2005 12:57 PM

RE: Open New Window from DataList Item...
 
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...



All times are GMT. The time now is 09:35 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.