Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

linkbutton thingy 1

Status
Not open for further replies.

mattbold

Programmer
Oct 5, 2001
45
GB
hello,

I have become a little stuck, basically i have a page with details about a particular music release, and on that page i have a repeater supplying a list of users (as linkbuttons)of the site who have written reviews of the music release, what needs to happen is when a user is clicked on in this list then their review should be displayed on a label on the page which is already there, i've been trying to get this to work by calling a function in my code behind, but this hasn't worked (i don't know if i've been going about it the right way, or if this is possible).

my aspx page code at the moment for this bit is:

<asp:repeater id=&quot;RepeaterReviews&quot; runat=&quot;server&quot;>
<ItemTemplate>
<asp:LinkButton id=&quot;Linkbutton2&quot; runat=&quot;server&quot; BackColor=&quot;#CCCCCC&quot;>
<%# container.dataitem(&quot;Username&quot;) %>
</asp:LinkButton>
<br>
</ItemTemplate>
</asp:repeater>

i tried making an onclick for the linkbutton but wasn't quite sure how to go about it...

if anyone could help that would be greatly appreciated. I'm sorry if i haven't been very clear on my problem, don't hesitate to request more details, i will be more than happy to oblige!

cheers,
matt

ps be excellent to each other
 
Matt: The Link button can be replaced with a hyperlink and you can post back with the city in a Querystring, and then populate the Label with the result. However, you question is valid, i.e., you should be able to execute code with a postback using the Link button. A work around, for the time being (I am going to continue to look into the use of the Link button, perhaps someone will post a solution, for the above stated purpose). The following code does what you want it to but uses a hyperlink instead of a link button:

In this case I am getting Counties and Cities and showing the selected County's city in the label:

Private Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
If Not IsPostBack Then
'open database...
Dim cmdSelect As OLEDbCommand
Dim dbconn As OleDbConnection = New OleDbConnection( _
&quot;Provider=Microsoft.Jet.OLEDB.4.0; &quot; & _
&quot;Data Source=&quot; & Server.MapPath(&quot;.\fpdb\Sites.mdb;&quot;))
cmdSelect = New OLEDbCommand(&quot;SELECT County, City FROM tblZipCodes&quot;, dbconn)
dbconn.Open()
RepeaterReviews.DataSource = cmdSelect.ExecuteReader()
RepeaterReviews.DataBind()
dbconn.Close()
End If
lblA.Text = Request.QueryString(&quot;City&quot;)
End Sub
</script>
<HTML>
<HEAD>
<title>Test Page</title>
</HEAD>
<body>
<form id=&quot;Form1&quot; method=&quot;post&quot; runat=&quot;server&quot;>
<p></p>
<p></p>
<asp:Label id=&quot;lblA&quot; runat=&quot;server&quot;/><br>
<asp:repeater id=&quot;RepeaterReviews&quot; runat=&quot;server&quot;>
<ItemTemplate>
<asp:hyperlink id=&quot;Linkbutton2&quot; runat=&quot;server&quot; Text='<%#container.dataitem(&quot;County&quot;)%>' NavigateUrl='<%# &quot;.\Test.aspx?City=&quot; & DataBinder.Eval(Container,&quot;DataItem.City&quot;)%>'/>
<br>
</ItemTemplate>
</asp:repeater>
</form>
</body>
</HTML>
 
Mat: The exact solution you are looking for is located at:


...it includes a Demo. The code is in C#. Will take a look at it. The advantage of the Link button over the hyperlink is the ability to execute additional code when the click event occurs.

FYI
 
cheers man! much appreciated thankyou very much!

 
matt: Thanks. Remember that with Linkbuttons they have to be created dynamically as they do not survive post back (unless you add additional code re: viewstate). However, as several examples show they are very valuable in that a link button can be coupled with code whereas a hyperlink is not as versatile. Many situations out there for the use of Linkbuttons.

Another good article on the Linkbutton, using the game &quot;Hangman&quot; as an example, along with the Demo code, can be found at:


I am going to continue to look at this and come up with an example in VB and re-post. I've been avoiding the Linkbutton but a review this morning, brought about by your question, brought home the importance of this feature of dot NET (we're all pretty much new at this - and thank God we have the likes of Paul, Zarc, Frost and others to help us along).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top