Reputation: 620
I would like to be able to change my html table when I select list item from the dropdown menu.
For example,
Updated HTML Logic:
<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>
<asp:Literal ID="litInfo" runat="server"></asp:Literal>
</tr>
</tbody>
<p><asp:DropDownList ID="ddlDate" runat="server" Width="200px" OnSelectedIndexChanged="myListDropDown_Change" AutoPostBack="True">
</asp:DropDownList></p>
weekly() function:
public string weekly()
{
string htmlStr = "";
SqlCommand cmd = con.CreateCommand();
cmd.CommandText = "select Deal, [property], [event], [Date] from [dbo].[Database_CRE]";
con.Open();
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
string name = reader.GetString(0);
string loan = reader.GetString(1);
string evnt = reader.GetString(2);
string b = linkTag(name);
htmlStr += "<tr><td>" + b + "</td>" + "<td>" + loan + "</td>" + "<td>" + evnt + "</td></tr>";
}
con.Close();
return htmlStr;
}
Updated Server Code:
protected void myListDropDown_Change(object sender, EventArgs e)
{
DropDownList ddl = FindControl("ddlDate") as DropDownList;
if (ddl != null)
{
if (ddl.SelectedIndex == 1)
{
litInfo.Text = weekly();
}
}
}
protected void Page_Load(object sender, EventArgs e)
{
//Add item to DropDownList
ddlDate.Items.Insert(0, "Select Timeline");
ddlDate.Items.Insert(1, "Weekly");
ddlDate.Items.Insert(2, "Monthly");
litInfo.Text = current();
}
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?
Any further help would be very much appreciated. Many thanks
Upvotes: 1
Views: 666
Reputation: 1090
Replace
<%=current()%>
with
<asp:Literal ID="litInfo" runat="server"></asp:Literal>
Then in the code behind add the following code
protected void Page_Load(object sender, EventArgs e)
{
litInfo.Text=current();
}
Now change your Change event to
protected void myListDropDown_Change(object sender, EventArgs e)
{
if (ddlDate.SelectedValue == "Weekly")
{
litInfo.Text= weekly();
}
else if (ddlDate.SelectedValue == "Monthly")
{
litInfo.Text=monthly();
}
}
Upvotes: 0
Reputation: 3204
You could use 3 Panels
here. Each with different HTML table template as you would like for weekly or monthly or whatever. Then just make only one of them visible at a time based on the Drop-down selection.
That way, you dont have to put much code in your code-behind and just have to play with the visibility
of those 3 Panels based on the selection.
Upvotes: 1