Click here to Skip to main content
15,914,016 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

I have this Code. It works the Images and the mouse over titel are showing. Now I wont to place a TextBox to write Information. The data should be saved in the database. My Problem is: I dont know how to find the correct ID; so the Information will be saved in the correct database line.

What I have tried:

protected void Save_Click(object sender, EventArgs e)
   {

       string constr = ConfigurationManager.ConnectionStrings["conn"].ConnectionString;
       using (SqlConnection conn = new SqlConnection(constr))
       {
           conn.Open();
           string query = @"UPDATE Pic SET desc=@desc where ID=@ID";
           using (SqlCommand cmds = new SqlCommand(query, conn))
           {
               cmds.Parameters.AddWithValue("@desc", txtdesc.Text);
               cmds.Parameters.AddWithValue("@ID", WHAT COMES HERE?);

               cmds.ExecuteNonQuery();
           }
       }

   }


<pre>protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
    {
        string a = "";
        string g = "";


        string x = TreeView1.SelectedNode.ValuePath.Replace("GO/", "");

        string sql = @"Select * From Pic  ORDER BY Place";
       

       
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ConnectionString);
        con.Open();
        SqlCommand cmd = new SqlCommand(sql, con);
        SqlDataReader r = cmd.ExecuteReader();
        int lb = 0;
        while (r.Read())
        {
               a += "<li><img src=\"/ImageHandler.ashx?id=" + r["ID"].ToString() + "\" alt=\"" + r["Text"].ToString() + "\"/></li>";
            g += "<a href=\"#\" title=" + r["title"].ToString() + "><img src=\"/ImageHandler.ashx?id=" + r["ID"].ToString() + "&width=35&height=16\" alt=\"\" /></a>";
            lb++;
        }
        con.Close();
        phBilder.Text = a;
        phTumbs.Text = g;
}
Posted
Updated 24-Feb-17 1:06am

1 solution

In img tag your are missing ID property 
add Id <img src=\"/ImageHandler.ashx?id=img" + r["ID"].ToString() + "&width=35&height=16\" alt=\"\" runat=\"server\" id=img" + r["ID"].ToString() + "/>


Use Jquery to get the all the ids in javascript. like below

var IDs = [];
           $("#a").find("img").each(function () { IDs.push(this.id); });


at UI

<div id="a" runat="server">

   </div>


Use String builder class and add your HTMLto the div id "a"
 
Share this answer
 
v3

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