Tuesday, August 18, 2009

Set OnClick Event with a string Parameter on LinkButton from ListView ItemDataBound (x_X)

Set OnClick Event with a string Parameter on LinkButton from ListView ItemDataBound (x_X)

Hello,

I got a label on my webform that i would like to rename when a product is selected inside a ListView.



DataSourceID="ProductsDataSource" GroupItemCount="5"
runat="server" onitemdatabound="ProductsListView_ItemDataBound1">
...









In code behind, on ListViewItemDatabound event, i did this :


((LinkButton)e.Item.FindControl("LinkButton1")).Click += new EventHandler(linkButton_Handle); //adding the new OnClick event to replace the default one

string str = DataBinder.Eval(DataItem.DataItem, "Prod_Nom").ToString(); // define a string who will be the Label1.text later on LinkButton_Handle event

((LinkButton)e.Item.FindControl("LinkButton1")).Attributes.Add("OnClick", String.Format("javascript:{0};", this.ClientScript.GetPostBackEventReference(this, str))); // adding the parameter to the javascript on LinkButton OnClick event


Here's the html i get from the output for example :


First problem : linkButton_Handle is never called (maybe linkbutton1 is constructed before ?)

Second problem : how can i use my 'Agenda 2009' parameter to set my Label1.text with that parameter ?


Starting to drive in crazy, Thanks for help.


View Full Details...............................

No comments:

Post a Comment