Click here to Skip to main content
11,632,715 members (82,057 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
Hi.. here am bind database images in grid view.. I set pagesize as 5.. If the images in grid exceeds 5 means the paging property not working properly.. Can anyone help me??

<asp:GridView ID="gvImages" runat="server" AllowPaging="True"
AutoGenerateColumns="False" CssClass="Gridview" HeaderStyle-BackColor="#446182"
HeaderStyle-ForeColor="white" OnPageIndexChanging="gvImages_PageIndexChanging"
OnRowCommand="gvImages_RowCommand" OnSelectedIndexChanged="gvImages_SelectedIndexChanged"
PageSize="4" Width="100">

<asp:TemplateField HeaderText="Image">


<asp:Image ID="Image1" runat="server" BorderColor="#446182" BorderWidth="2" Height="150px"
ImageUrl='<%# "~/Image.aspx?id="+Eval("id") %>' Width="150px" />
<asp:HiddenField ID="hf1" runat="server" Value='<%# Eval("id") %>' />




<asp:TemplateField HeaderText="Remove">


<asp:Button ID="BtnRemove" runat="server" BackColor="#446182" BorderColor="#446182"
CommandName="Remove" CssClass="txt" Text="Remove" />






PageButtonCount="4" />

<HeaderStyle BackColor="#446182" ForeColor="White" />


.cs
protected void gvImages_RowCommand(object sender, GridViewCommandEventArgs e)
{
try
{
lbldel.Text = "";

if (e.CommandName == "Remove")
{

GridViewRow row = (GridViewRow)((Control)e.CommandSource).NamingContainer ;
// (or) //
// GridViewRow row = (GridViewRow)((Control)e.CommandSource).Parent.Parent;
index = row.RowIndex;


HiddenField id1 = (HiddenField)gvImages.Rows[index].FindControl("hf1");

if (dbo.deleterecords("image", "id='" + id1.Value + "'") == true)
{
bindgrid();
lbldel.Text = "Image Deleted";
}
}
}
catch (Exception ex)
{
Exception E = ex;
}
}
protected void gvImages_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
try
{
gvImages.PageIndex = e.NewPageIndex;
bindgrid();
}
catch (Exception ex)
{
}
}

public void bindgrid()
{
try
{
DataTable dt = dbo.GetRecordsWithQuery("Select '' as Sno,id,image,'Remove' as [Remove] from image");
gvImages.DataSource = dt;
gvImages.DataBind();

}
catch (Exception ex)
{
Exception E = ex;
}

}
Posted 24-Jan-13 23:53pm
Edited 25-Jan-13 0:04am
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Can u show ur code , so i can see where ur wrong
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 8,498
1 Sergey Alexandrovich Kryukov 8,149
2 Mika Wendelius 6,260
3 F-ES Sitecore 2,321
4 Suvendu Shekhar Giri 1,995


Advertise | Privacy | Mobile
Web03 | 2.8.150728.1 | Last Updated 25 Jan 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100