Alternative to DataPager


I am using a datapager on a page where different images are shown. Now i am using the following code:-

        <asp:DataPager ID="DataPager1" runat="server" 
        PagedControlID="lvPhotoViewer" PageSize="1" 
            <asp:NextPreviousPagerField ButtonType="Link"
            PreviousPageText="<< Previous" NextPageText="Next >>"/>

Now this code does run through all the images, but i need to alter the querystring and make it change to match the ID of the photo displayed. I tried adding QueryStringField=“String” but this was hopeless.

I have a querystring like so:-

When i click on next image i need it to change to something like:-

See the PhotoID has changed. But it currently does not do this. When i arrive on the page the PhotoID stays the same. I have been trying for a while and im starting to give up!

So was wondering if there was an alternative.



I actually tried doing this:-

            if (SourceTextBox != null)
                DataPager1.QueryStringField = "view-photo.aspx?PhotoID=" + SourceTextBox.Text + "&AlbumID=" + Request.QueryString["AlbumID"].ToString() + "&UID=" + Request.QueryString["UID"].ToString() + "";

But it didnt work. I have an invisible label which holds the value of the ID of the photo.

So i thought i would simply get the value of it. But it does not work.

Any ideas?

DataPager1.QueryStringField should be the name of the Query string you want to change. PhotoID

Note that this will issue a GET instead of a PostBack.


well i thought the same thing but this code does nothing to the querystring, it does not change the PhotoID.

This is the code, there is quite a bit sorry!

    protected void Page_Load(object sender, EventArgs e)
        if (!Page.IsPostBack)
            string photoID = Request.QueryString["PhotoID"];
            string albumID = Request.QueryString["AlbumID"];
            ViewState["hfAlbumID"] = albumID;
            //Get Page number by passing photo id
            int index = GetPageNumber(int.Parse(photoID), int.Parse(albumID));
            DataPager1.SetPageProperties(index, 1, true);

            Label SourceTextBox = (Label)Page.PreviousPage.FindControl("Label5");

            if (SourceTextBox != null)
[B]                DataPager1.QueryStringField = "view-photo.aspx?PhotoID=" + SourceTextBox.Text + "&AlbumID=" + Request.QueryString["AlbumID"].ToString() + "&UID=" + Request.QueryString["UID"].ToString() + "";[/B]
    /// <summary>
    /// Since the pagesize is 1 the row number can be taken as page number
    /// </summary>
    /// <param name="PhotoID"></param>
    /// <param name="AlbumID"></param>
    /// <returns></returns>
    public int GetPageNumber(int PhotoID, int AlbumID)
        SqlConnection con = new SqlConnection("Data;User ID=wbsd;Password=******");
        SqlCommand com = new SqlCommand("SELECT PageNumber FROM (SELECT row_number() Over (order by photo_id asc) AS PageNumber,photo_id,album_id FROM hussaini_photo_album where album_id=" + AlbumID.ToString() + ") As photos where photo_id=" + PhotoID.ToString() + " and album_id=" + AlbumID.ToString(), con);
        SqlDataReader dr = com.ExecuteReader();
        int pageno = 1;
        if (dr.Read())
            pageno = int.Parse(dr["PageNumber"].ToString());
        return (pageno - 1);
    public DataTable GetPhoto(string query)
        SqlConnection con = new SqlConnection("Data;User ID=wbsd;Password=******");
        SqlDataAdapter ada = new SqlDataAdapter(query, con);
        DataTable dtEmp = new DataTable();
        return dtEmp;
    protected void DataPager1_PreRender(object sender, EventArgs e)
        lvPhotoViewer.DataSource = GetPhoto("Select * from hussaini_photo_album where album_id = " + ViewState["hfAlbumID"].ToString());
    protected void lvPhotoViewer_SelectedIndexChanged(object sender, EventArgs e)


See the code in bold. Any ideas why it does not work?