连接到Sql Server数据库并检索主题 [英] Connect to Sql Server database and retrieve themes

查看:103
本文介绍了连接到Sql Server数据库并检索主题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我这里有一个任务,该任务涉及从Sql服务器数据库中检索图像并将其显示在div中.我目前正在使用Jquery在div中显示图像.我的任务是以某种方式连接Jquery函数,以便在单击按钮时可以更改主题.代码在这里.我会很感激您的帮助.

aspx:

Hi
I have a task here which deals with retrieving Images from Sql server database and display them in a div. I am currently using Jquery for displaying the images in a div. My task is to connect the Jquery function in such a way that themes should change on button click. Code for that goes here. I would be thankful for the help.

aspx:

aspx:

<script>

style type="text/css">

     #yu {
    width:300px;
    height:420px;
       }

    p {
    font-family:Verdana;
    font-weight:bold;
    font-size:11px
    }
     </style>


 <script language="javascript" type="text/javascript">
   function changeDivImage() {
         var imgPath = new String();
         imgPath = document.getElementById("yu").style.backgroundImage;
         document.getElementById("yu").style.backgroundImage = "url(charttheme/blue.jpg)";
         }

</script>

<body>
<div></div>

<input type="button" value="preview" onclick="changeDivImage()" />
</body>

推荐答案


我想我无法回答您的问题,因为您的意思是对不起
但是如果您想更改DIV的背景图像,并且数据库中有图像URL,则为
因此,对我而言,最好的解决方案是使div在服务器上运行,并从
后面的代码开始设置样式
这是ASPX页面
Hi,
I think that i can''t get your question as you mean it sorry for that
but if do u want to change the background image of DIV and you have the images URL in your Database
so the best solution for me right now is to make the div run at server and start to set the style from the code behind

this is the ASPX page
<body>
    <form id="form1" runat="server">
    <div id="yu" runat="server"></div>
    <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />

    </form>
</body>




这是Button1的click事件的代码.




And this is the code of click event of the Button1

yu.Style.Add("background-image", "url('imgs/S(1).jpg')");
yu.DataBind();



您可以使用数据库中的图像URL更改 imgs/S(1).jpg
另一个 使用Java代码设置背景图片的方法

您可以修改名为changeDivImage的函数,使其能够像这样通过动态更改图片网址



you can change this imgs/S(1).jpg with the Image URL you have in your Database

Another Way to set the background image with Javascript code

you can modify the function called changeDivImage to be able to change the image url dynamically by make it like this

<script language="javascript" type="text/javascript">
 function changeDivImage(imgUrl) {
     var imgPath = new String();
     imgPath = document.getElementById("yu").style.backgroundImage;
     document.getElementById("yu").style.backgroundImage = "url('" + imgUrl + "')";
 }

</script>




然后从后面的代码中调用您想要的图像URL,以触发javascript函数




then from the code behind you have to call the image URL you want like this to fire the javascript Function

string ImgPath = "the retrieved image URL from the Database";
     ScriptManager.RegisterStartupScript(this, this.GetType(), "starScript", "changeDivImage('" + ImgPath + "');", true);


问候,
艾哈迈德·曼杜尔(Ahmed Mandour)


Regards,
Ahmed Mandour


这篇关于连接到Sql Server数据库并检索主题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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