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

dynamically populateing asp.net menu

Status
Not open for further replies.

gtjr921

Programmer
Aug 30, 2006
115
ASP.Net 2.0
I have a asp menu control that has dynamic links depending on the value of the EMPID
For instance if a employee record also has a 'HID'
then the menu would be something like
Health and the navigate url value would be like health.aspx?empid=509 i also change the text value depending
on if the employee has the 'HID' so in this instance the text would be health. If there was not a HID then the text would be Add Health.
The text changing according to the HID works fine.
However for some reason the EMPID/Qstring value will not change on the menu. For instance if i change my selected value everything changes to reflect the different employee id except the (0) value in my menu.
My temp labels lbl98 & lbl99 changes to show the correct id but the naviagateurl {0}value does not
For instance i get employee id 509 then i change to employee id 1234, the link in the menu still shows id 509, the text of the url changes, but not the id. See my code below
FYI there is no datasource for this menu it is static in my asp. See my code i hope that explains more.
Thanks
.Net 2 Code
Code:
 <asp:Menu ID="Menu1" runat="server"   Orientation="Horizontal" 
    <StaticMenuItemStyle  Font-Size="Small"  />
              <DynamicItemTemplate>
            <%# Eval("Text") %>
        </DynamicItemTemplate>
        <Items>
            <asp:MenuItem NavigateUrl="~/empdetail.aspx" Text="Home/Search" Value="Home/Search">
            </asp:MenuItem>
            <asp:MenuItem  NavigateUrl="~/HealthDetails.aspx{0}" Text="Health" Value="Health"></asp:MenuItem>
            <asp:MenuItem NavigateUrl="~/empDental.aspx{0}" Text="Dental" Value="Dental"></asp:MenuItem>
            <asp:MenuItem NavigateUrl="~/EmpVision.aspx{0}" Text="Vision" Value="Vision"></asp:MenuItem>
            <asp:MenuItem NavigateUrl="~/Aflac.aspx{0}" Text="Aflac" Value="Aflac"></asp:MenuItem>
            <asp:MenuItem Text="Dependents" Value="Dependents" NavigateUrl="~/Depend.aspx{0}"></asp:MenuItem>
            <asp:MenuItem NavigateUrl="~/empadd.aspx" Text="Add New Employee" Value="Add New Employee">
            </asp:MenuItem>
        </Items>
    </asp:Menu>

VB
Code:
 Protected Sub FviewBind(ByVal sender As Object, ByVal e As System.EventArgs) Handles FormView1.DataBound
                Dim FVI As FormView = FormView1
         
        If FormView1.DataItemCount > 0 Then
'Find the Employee ID
 Dim qstring As String = CType(FVI.FindControl("lblEmpID"), Label).Text
            Dim qstringNEW As String = CType(FVI.FindControl("lblEmpID"), Label).Text + "&Action=NEW"
'Find health id
            Dim HID As String = CType(FVI.FindControl("lblHIDadd"), Label).Text
           'temp labels to make sure the empid is being read 'properly
            lbl98.Text = qstringNEW
            lbl99.Text = qstring
'find out if this employee also has a HID 
            If HID = "" Then
               'append the qstring value to the URL
                Menu1.Items.Item(1).NavigateUrl = String.Format(Menu1.Items.Item(1).NavigateUrl.ToString(), "?EmpID=" + qstringNEW)
                Menu1.Items.Item(1).Text = "Add Health"

            Else

                Menu1.Items.Item(1).NavigateUrl = String.Format(Menu1.Items.Item(1).NavigateUrl.ToString(), "?EmpID=" + qstring)
            End If
 
I figured it out I just had to disable viewstate for the menu control!
 
just wondering why you didn't make the menu items data driven..meaning getting the values from a table?
 
Because the datasource would not allow me to manipulate it in such a way that i could add the id variables to the navigate url fields. I tried it but it just would not do it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top