LinkButton within DataList

How to pass a DataList value to a label control

Page 1 of 1

0 Replies - 6189 Views - Last Post: 02 April 2009 - 09:14 AM Rate Topic: -----

#1 awwyeh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 15-February 09

LinkButton within DataList

Posted 02 April 2009 - 09:14 AM

Hello - I am in the process of re-creating an existing website where the ownership has decided to start from scratch.

An example of the OLD/current site is here: http://www.mentalhea...l?therapistId=4

Instead of using IFrames and server-side includes withing those IFrames, I am developing the functionality using a combination of ASP.NET controls.

If you look at the page associated with the above link, the object of my confusion is the PREFERENCES area on the right-side of the page. Currently the website allows visitors to click the green plus signs to add an item to the Preferences area. Once the item is placed in the Preferences area, a visitor can remove them by clicking a red x next to the item.

I am attempting to imitate this functionality using LINKBUTTONS within a DATALIST - and, frankly, I am uncertain how to do this.

The information from the DataList is dependent on a DetailsView control placed at the top of the page - both work very well. I'm just stuck how to get the LinkButton within the DataList to pass the value of the DataList item.

I should note that I'm only assuming this will be tied to a LABEL control, which I have on the page named "lblText", it's just not in the source provided below.

Here is the code for the DataList control:

<asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSourceOffice" DataKeyField="officeID">
		<ItemTemplate>
			OfficeName:
			<asp:Label ID="OfficeNameLabel" runat="server" 
				Text='<%# Eval("OfficeName") %>' />
			<br />
			<asp:LinkButton ID="LinkButton1" runat="server" CommandName="Select" CommandArgument='<%# Eval("OfficeName") %>' onclick="LinkButton1_Click" >LinkButton</asp:LinkButton>
			<br />
			<br />
		</ItemTemplate>
	</asp:DataList>



Here is the code behind - clearly NOT even close. I'm just not sure how to proceed.

Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
		lblText.Text = DataList1.SelectedValue.ToString
	End Sub
End Class



Thank you for any assistance you might be able to provide.

Is This A Good Question/Topic? 0
  • +

Page 1 of 1