Click here to Skip to main content
15,881,852 members
Please Sign up or sign in to vote.
1.44/5 (2 votes)
Hi,

I would like to be able to change my html table when I select list item from the dropdown menu.

For example,

Currently, when the page loads, the html table only renders current method.
C#
 <tbody>
<tr>
<th><asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></th>
<th><asp:TextBox ID="TextBox2" runat="server"></asp:TextBox></th>
<th><asp:TextBox ID="TextBox3" runat="server"></asp:TextBox></th>
</tr>
<tr>
<%=current()%>
</tr>
 </tbody>


I would like to build logic for, If I select weekly option from the dropdown menu, I would like the html table to render the weekly().method.

Would I need to create this login inside the current() method. if so, how would I
pass the dropdown event method?

Current progress:
C#
protected void myListDropDown_Change(object sender, EventArgs e)
        {
            DropDownList ctrl1 = FindControl("ddlDate") as DropDownList;
            if (ctrl1.SelectedValue == "Weekly")
            {
                string week = weekly();
                // not sure how to implement after this stage...???
                
            }

        }


ASP.NET
<p><asp:DropDownList ID="ddlDate" runat="server" Width="200px" OnSelectedIndexChanged="myListDropDown_Change">
              <asp:ListItem Text="Select Timeline" Value=""></asp:ListItem>
              <asp:ListItem Text="Weekly" Value=""></asp:ListItem>
              <asp:ListItem Text="Monthly" Value=""></asp:ListItem>
          </asp:DropDownList></p>


Any further help would be very much appreciated. Many thanks
Posted
Updated 11-May-15 0:16am
v2

1 solution

I would advise you to use a single method that will render the correct content by checking the selected value...After all that method runs on the server in the very same page where the drop-down is...
HTML
<table><tbody><tr>
  <%=render()%>
</tr></tbody></table>

C#
public string render()
{
  swtich(dropdown.SelectedValue)
  {
     case: 1:
     {
     }
     break;

     case: 2:
     {
     }
     break;
  }
}

The Change method of drop-down will be used only for page refresh...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900