可以将命令参数和onclick事件添加到div吗? [英] Can command argument and onclick event be added to a div?
问题描述
我有一张相册(不是图库),用它预览照片。根据与用户关联的专辑数量动态生成专辑。我想在其上添加点击事件,以便当一个人点击一个专辑时,它会将他带到该专辑中的照片。我是初学者所以我不知道如何做到这一点。但我认为添加命令参数应该可以解决问题。
ASPX代码:
for(int i = 0; i < dt5.Rows.Count; i ++)
{
string q = 从照片中选择imageurl,其中albumid ='
< span class =code-attribute> + < span class =code-attribute> dt5.Rows [i] [albumid]。ToString() + ';
dt6 = dbo.Getdt(q) ;
a = dt6.Rows [0] [ imageurl]。ToString();
b = dt6.Rows [1] [ imageurl]。ToString();
c = dt6.Rows [2] [ imageurl]。ToString();
a = a.Substring(1, a.Length - 1);
b = b.Substring(1, < span class =code-attribute> b.Length - 1);
c = c.Substring(1, c.Length < span class =code-attribute> - 1);
% >
< div id = Div1 class < span class =code-keyword> = image_stack style = margin-removed300px;已删除418px;
runat = 服务器 >
< img id = Img1 class = stackphotos photo1 src = <%:a%> / >
< img id = Img2 class = stackphotos photo2 src = <%:b%> / >
< img id = Img3 class = stackphotos photo3 src = <%:c%> / >
< / div >
< br / > < ; br / < span class =code-keyword>> < br / > < br / >
<%}%>
在上面的代码中,image_stack是div,它用于使用Jquery插件显示相册。
你无法添加Div / Panel控件的CommandArgument / Comamnd事件
您可以添加LinkButton / ImageButton或Button来满足您的要求,并将该按钮添加到Div
< div id = Div1 < span class =code-keyword> class = image_stack >
runat = server < span class =code-keyword>>
< asp:linkbutton id = linkButton text = text commandargument = 1 commandname = GetAlbum runat = server xmlns:asp = #unknown >
< img id = Img1 class = stackphotos photo1 >
< img id = Img2 class = stackphotos photo2 >
< img id = Img3 class = stackphotos photo3 >
< / div >
I am have a photo album(not gallery) which previews the photos withing it. The albums are dynamically generated depending on number of albums associated with the user. I want to add on click event to it so that when a person clicks an album it takes him to the photos within that album. I am beginner so I do not exactly know how it can be done. But I think adding command arguments should do the trick.
ASPX CODE:
for (int i = 0; i < dt5.Rows.Count; i++)
{
string q = "select imageurl from photos where albumid='"
+ dt5.Rows[i]["albumid"].ToString() + "'";
dt6 = dbo.Getdt(q);
a = dt6.Rows[0]["imageurl"].ToString();
b = dt6.Rows[1]["imageurl"].ToString();
c = dt6.Rows[2]["imageurl"].ToString();
a= a.Substring(1, a.Length - 1);
b = b.Substring(1, b.Length - 1);
c = c.Substring(1, c.Length - 1);
%>
<div id="Div1" class="image_stack" style="margin-removed300px ; removed 418px;"
runat="server">
<img id="Img1" class="stackphotos photo1" src="<%: a %>" />
<img id="Img2" class="stackphotos photo2" src="<%: b %>" />
<img id="Img3" class="stackphotos photo3" src="<%: c %>" />
</div>
<br /><br /><br /><br />
<% } %>
In above code image_stack is the div which is used to show album using Jquery plugin.
You can not add CommandArgument/Comamnd Event to Div/Panel control
Instead of it you can add on LinkButton / ImageButton or Button to fulfil your requirement and Add that button to Div
<div id="Div1" class="image_stack"> runat="server"> <asp:linkbutton id="linkButton" text="text" commandargument="1" commandname="GetAlbum" runat="server" xmlns:asp="#unknown"> <img id="Img1" class="stackphotos photo1"> <img id="Img2" class="stackphotos photo2"> <img id="Img3" class="stackphotos photo3"> </div>
这篇关于可以将命令参数和onclick事件添加到div吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!