2) Please find the Data base table data which i have used.
3)ASPX Code:
<table>
<tr>
<td>
<asp:DataList ID="dlMenu" TabIndex=1 runat="server" RepeatDirection="Horizontal"
CellSpacing="3" Height="154px" Width="908px">
<ItemTemplate>
<asp:Label ID="ReportName" runat="server" Text='<%# Eval("ImageName") %>' />
<br />
<a href='<%# Eval("ImagePath") %>' ">
<img src='<%# Eval("ImagePath") %>' style="height: 100px; width: 100px;border: 1px solid gray;" />
</a>
</ItemTemplate>
</asp:DataList>
</td>
</tr>
</table>
<table border="0" style="width: 928px">
<tr>
<td align="center" >
<asp:ImageButton ID="imgfirst" runat="server" ToolTip = "First Button" ImageUrl="~/Images/first.gif" onclick="imgFirst_Click" />
<asp:ImageButton ID="ImgPrevious" runat="server" ToolTip = "Previous Button" ImageUrl ="~/Images/prev.gif" onclick="ImgPrevious_Click" />
<asp:ImageButton ID="imgNext" runat="server" ToolTip = "Next Button" ImageUrl="~/Images/next.gif" onclick="imgNext_Click" />
<asp:ImageButton ID="imgLast" runat="server" ToolTip = "Last Button" ImageUrl="~/Images/last.gif" onclick="ImgLast_Click" />
</td>
</tr>
</table>
.4) Aspx.cs File Code
Int32 IntCurrentPageIndex = 0;
PagedDataSource pgd = newPagedDataSource();
protected voidPage_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
IntCurrentPageIndex = 0;
this.ViewState["Data"] = 0;
IntCurrentPageIndex = (int)this.ViewState["Data"];
BindImagesData();
}
}
protected voidBindImagesData()
{
DataSet dsImage = newDataSet();
SqlConnectioncon = new SqlConnection("Data Source=CHANDU-PC\\SQLEXPRESS;Initial Catalog=Test;Integrated Security=True");
con.Open();
SqlCommand cmd = newSqlCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "Select * FROM tbl_ImagesData";
SqlDataAdapter da = newSqlDataAdapter(cmd);
da.Fill(dsImage);
try
{
if (dsImage.Tables.Count > 0)
{
if (dsImage.Tables[0].Rows.Count > 0)
{
pgd.DataSource = dsImage.Tables[0].DefaultView;
pgd.CurrentPageIndex = IntCurrentPageIndex;
pgd.AllowPaging = true;
pgd.PageSize = 7;
pgd.CurrentPageIndex = IntCurrentPageIndex;
dlMenu.DataSource = pgd;
dlMenu.DataKeyField = "ImageID";
dlMenu.DataBind();
con.Close();
}
}
}
catch (Exceptionex)
{
}
}
protected voidImgLast_Click(object sender, ImageClickEventArgs e)
{
IntCurrentPageIndex = pgd.PageCount - 1;
BindImagesData();
}
protected voidimgFirst_Click(object sender, ImageClickEventArgs e)
{
IntCurrentPageIndex = 0;
BindImagesData();
}
protected voidImgPrevious_Click(object sender, ImageClickEventArgs e)
{
IntCurrentPageIndex = (int)this.ViewState["Data"];
IntCurrentPageIndex--;
this.ViewState["Data"] = IntCurrentPageIndex;
BindImagesData();
}
protected voidimgNext_Click(object sender, ImageClickEventArgs e)
{
IntCurrentPageIndex = (int)this.ViewState["Data"];
IntCurrentPageIndex++;
this.ViewState["Data"] = IntCurrentPageIndex;
BindImagesData();
}
No comments:
Post a Comment