I get DataTable from Access DB of suggestions and when i create foreach loop i create how it will look in the web here is the code:
public partial class suggestions : System.Web.UI.Page{
protected string str = "";
protected string str1 = "";
protected int id = 0;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataTable dt = myadohelper.ExecuteDataTable("YonatanDB.mdb", "select * from suggestionsTable");
foreach (DataRow row in dt.Rows)
{
int like = int.Parse(row["likeCount"].ToString());
int dislike = int.Parse(row["dislikeCount"].ToString());
int score = like - dislike;
str += "<div class='sug'>";
str += "<div class='txt'>";
str += "<h3>" + row["suggestionName"] + "</h3>";
str += "<p>" + row["suggestion"] + "</p>";
str += "</div>";
str += "<div class='like'>";
str += "<button type='button' id='btnLike" + row["ID"] + "' runat='server' onserverclick='Action_Click' ><img src='img/like.png' alt='Italian Trulli'/></button>";
str += "<button type='button' id='btnDisLike" + row["ID"] + "' runat='server' onserverclick='Action_Click' ><img src='img/dislike.png' alt='Italian Trulli'/></button>";
str += "<div class='likeNumber'>ציון: " + score + "</div>";
str += "</div>";
str += "</div>";
str += "<br />";
}
}
}
protected void Action_Click(object sender, EventArgs e)
{
HtmlButton b = sender as HtmlButton;
string s = "";
if (b != null)
{
s = b.ClientID;
}
str1 = "<p>" +s + "</p>";
}
}
and here is the HTML code:
<form id="my_form" method="post" runat="server">
<h1>Main Suggestion</h1>
<%=str1 %>
<br /><br />
<%=str %>
</form>
I'm trying to activate a function in Asp.net named "Action_click" from the buttons (the names of the buttons are "btnLike" and "btnDisLike" each id i added the id from the DB) i created,
for for some reason the function don't work and i dont know why?
p.s. for now the function only add a paragraph to the HTML page, but when i see it's warking i'll change it.