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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Redirecting URL with DList Linkbutton

Status
Not open for further replies.

Isadore

Technical User
Feb 3, 2002
2,167
US
This is mainly a tip for beginners, and those looking at the DataList as an option. Its primary benefit is its nearly unlimited formatting capabilites --

In this example there is a DropDownList and a DataList. In the DataList, among various objects, is a linkbutton which functions to redirect the page based on the selected value in the nearby DropDownList.

Within the DataList structure the linkbutton as:

<asp:linkbutton
id=&quot;lnkSite&quot;
runat=server
Forecolor=&quot;red&quot;
Font-bold=&quot;true&quot;
CommandArgument=<%# Container.DataItem(&quot;AwwSiteCode&quot;)%>
OnCommand=commandHandler>
<%# Container.DataItem(&quot;AwwSiteCode&quot;)%>
</asp:linkbutton>

The OnCommand event is:

Protected Sub commandhandler(sender As Object, e As CommandEventArgs)
If ddChart.SelectedItem.Text = &quot;Chemistry Histories&quot; Then
Response.Redirect(&quot;ddChemHistory.aspx?AwwSiteCode=&quot; & e.CommandArgument)
ElseIf ddChart.SelectedItem.Text = &quot;Chemistry Real Time&quot; Then
Response.Redirect(&quot;ChemRT.aspx?AwwSiteCode=&quot; & e.CommandArgument)
ElseIf ddChart.SelectedItem.Text = &quot;Bacteria Histories&quot; Then
Response.Redirect(&quot;ddBacHistory.aspx?AwwSiteCode=&quot; & e.CommandArgument)
Else
Response.Redirect(&quot;BacRT.aspx?AwwSiteCode=&quot; & e.CommandArgument)
End If
End Sub

Where the &quot;e.CommandArgument&quot; completes the QueryString and the page is then properly redirected.

fyi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top