如何从标签中存储的图像中查找ID? [英] How to find ID from images stored in labels?

查看:92
本文介绍了如何从标签中存储的图像中查找ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我有这个代码。它适用于图像和鼠标在标题上显示。现在我不会放置TextBox来写信息。数据应保存在数据库中。我的问题是:我不知道如何找到正确的ID;所以信息将保存在正确的数据库行中。



我尝试过:



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;
}

推荐答案

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() + "/>





使用Jquery获取javascript中的所有ID。如下所示





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

var IDs = [];


(#a)。find( img)。each(function(){IDs.push(this.id);});
("#a").find("img").each(function () { IDs.push(this.id); });




用户界面






at UI

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

   </div>





使用字符串构建器类并将HTML添加到div ida



Use String builder class and add your HTMLto the div id "a"


这篇关于如何从标签中存储的图像中查找ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆