Open New Window from DataList Item...

G

Guest

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...
 
M

Mr Newbie

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.
 
G

Guest

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top