本文介绍了如何在asp.net中创建图库。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想创建艺术画廊。我正在使用datalist在gallery中显示艺术图像。它正在工作。现在,我想在单击图像时显示该艺术细节。但点击该图片后没有任何事情发生。请帮忙。
这是我的代码:
gallery.aspx:
I want to create art gallery. And I am using datalist to display images of arts in gallery.And it working. Now I want to display that art details when I click on Image. But nothing is happening after clicking on that image. Please help.
Here is my code:
gallery.aspx:
<asp:UpdatePanel ID="up1" runat="server">
<ContentTemplate>
<asp:DataList ID="DataList1" runat="server" RepeatDirection="Horizontal" RepeatColumns="4" OnItemCommand="DataList1_ItemCommand" DataKeyField="artsId" >
<ItemTemplate>
<table>
<tr>
<td>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("artsId") %>' Visible="false"></asp:Label>
</td>
<td>
<asp:ImageButton ID="ImageButton1" runat="server" Text='<%# Eval("mainImage") %>' Height="200px" Width="200px" CommandName="ImageButton1" ImageUrl='<%# Eval("mainImage") %>' />
</td>
</tr>
</table>
<br />
</ItemTemplate>
</asp:DataList>
</ContentTemplate>
</asp:UpdatePanel>
和我的C#代码是:
and my C# code is:
SqlConnection con = new SqlConnection("Data Source=SNEHAL-PC\\SNEHAL1;Initial Catalog=artsondeals;Integrated Security=True");
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
binddata();
}
}
protected void binddata()
{
DataSet ds = new DataSet();
DataTable dt = new DataTable();
con.Open();
string cmdr = "select arts.artsId,artdetails.mainImage from artdetails INNER JOIN arts ON artdetails.artsId=arts.artsId";
SqlCommand cmd = new SqlCommand(cmdr, con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
DataList1.DataSource = dt;
DataList1.DataBind();
}
protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
{
DataSet ds = new DataSet();
DataTable dt = new DataTable();
String str = "select artdetails.artDescription,arts.Name from artdetails INNER JOIN arts ON artdetails.artsId=arts.artsId";
SqlDataAdapter ad = new SqlDataAdapter(str, con);
ad.Fill(dt);
GridView gd = new GridView();
gd.DataSource = dt;
gd.DataBind();
}
推荐答案
这篇关于如何在asp.net中创建图库。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!