/    Sign up×
Community /Pin to ProfileBookmark

click button show div

Hello,

I have made code, when you click on the button then the div show, but this is not working. I use jquery for to show the div.

Can someone help me?

How can I show the div showData (with data from the database) when you click on the button?

thanks in advance.

default.aspx

[CODE]
<form id=”form1″ runat=”server”>
<p>
<asp:Button ID=”btn_sort_naam” runat=”server” OnClick=”btn_sort_naam_Click” Text=”Order by name” />

</p>

</form>

<div id=”showData” runat=”server”>
<asp:PlaceHolder ID=”PlaceHolder1″ runat=”server”></asp:PlaceHolder>

</div>
[/CODE]

default.aspx.cs

[CODE]
protected void btn_sort_naam_Click(object sender, EventArgs e)
{

if (!this.IsPostBack)
{
//Populating a DataTable from database.
DataTable dt = this.GetData();

//Building an HTML string.
StringBuilder html = new StringBuilder();

//Table start.
html.Append(“<table id=’owntable’ border = ‘1’>”);

//Building the Header row.
html.Append(“<tr>”);
foreach (DataColumn column in dt.Columns)
{
html.Append(“<th>”);
html.Append(column.ColumnName);
html.Append(“</th>”);
}
html.Append(“</tr>”);

//Building the Data rows.
foreach (DataRow row in dt.Rows)
{
html.Append(“<tr>”);
foreach (DataColumn column in dt.Columns)
{
html.Append(“<td>”);
html.Append(row[column.ColumnName]);
html.Append(“</td>”);
}
html.Append(“</tr>”);
}

//Table end.
html.Append(“</table>”);

//Append the HTML string to Placeholder.
PlaceHolder1.Controls.Add(new Literal { Text = html.ToString() });
}
}

private DataTable GetData()
{

using (SqlConnection con = new SqlConnection(“Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\Name\Documents\ASP\Folder\App_Data\Databse.mdf;Integrated Security=True”))
{
using (SqlCommand cmd = new SqlCommand(“SELECT * FROM Artikelen ORDER BY Naam”, con))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
using (DataTable dt = new DataTable())
{
sda.Fill(dt);
return dt;
}
}
}
}
}
[/CODE]

jquery

[CODE]
$(document).ready(function () {
$(“#btn_sort_naam”).click(function () {
$(“#showData”).slideToggle(“slow”);
});
});
[/CODE]

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@jedaisoulAug 21.2016 — Hi,

As this is a JQuery issue I've moved the thread to the JS frameworks forum. I haven't looked at your code in detail, but I wonder why you are building the div dynamically instead of manipulating the z-index, display, opacity or visibility properties? Also, why are you putting the div in a table?
×

Success!

Help @wesley5 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.14,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...