I have a page with a table that has rows of translated and untranslated text from a specific project. (This is being rendered in a loop programmatically when I'm reading from database). I also have a search box that has filters for the query. For the overall rendering of the rows, the paging links work fine (shows 10 rows per page) but when I search for a keyword, only the first page shows the rows of the filtered query. When I click the 2nd page link, it reverts back to the 2nd page of the overall rows (without filters). I'm assuming I should keep the search keyword and if it's in search mode in a Session variable but I'm unsure of how to do that exactly...
Example of how I'm rendering the query. I wrote the query this way to be able to reuse my query when filtering for the search keyword.
string query = @"select * from (SELECT ROW_NUMBER() OVER (ORDER BY " + sortByValue + @") AS
NUMBER, *
FROM tableS s
left join tableT t
on s.source_text_id = t.source_text_id and t.language_id = @LanguageID
left join users u
on t.user_id = u.user_id
where " + searchWhereClause + searchQuery + @") AS TBL
where number between ((@PageNumber - 1) * @RowspPage + 1) and (@PageNumber * @RowspPage)
order by " + sortBy;"
using (SqlConnection conn = new SqlConnection(connStr))
{
using (SqlCommand cmd = new SqlCommand(query, conn))
{
conn.Open();
//parameters are created here
using (SqlDataReader dr = cmd.ExecuteReader())
{
try
{
while (dr.Read())
{
//get and assign variables here
if (text.Contains(@"\n"))
{
results += "<tr><td> </td><td style=\"width:5%\"><input
id=\"copy" + counter + "\" type=\"button\" value=\"↘\"
onclick=\"doCopy(" + counter + ",'" + text + "');\"" + "/></td>"+
"<td><b id=\"" + counter +" \">" + text + " </b><i>(" + source + ")</i>" + "</td></tr>" +"<tr><td> </td><td><span id=\"dot" + counter + "\" style=\"color:" + statusColor + "\">" + "■</span></td>" +
"<td>" + "<TextArea onfocus=\"beginEdit(" + counter + "," + sourceTextID + ");\" onblur=\"endEdit(" + counter + ")\"" + "ID=\"text" + counter + "\"" + "style=\"width:90%\" TextMode=\"MultiLine\" Rows=\"2\">" + translatedText + "</textarea></td>" +
"<td><p style=\"font-size: 12px !important;\">Last Translated: " + lastMod + " by " + initials + "</p></td>" +
"</tr>";
}
else
{
results += "<tr><td> </td><td><input id=\"copy" + counter + "\" type=\"button\" value=\"↘\" onclick=\"doCopy(" + counter + ",'" + text + "');\"" + "/></td>" +
"<td><b id=\"" + counter +" \">" + text + " </b><i>(" + source + ")</i>" + "</td></tr>" +
"<tr><td> </td><td><span id=\"dot" + counter + "\" style=\"color:" + statusColor + "\">" + "■</span></td>" +
"<td><input onfocus=\"beginEdit(" + counter + "," + sourceTextID + ");\" onblur=\"endEdit(" + counter + ")\"" + "id=\"text" + counter + "\"" + "style=\"width:90%\"" + "type=\"text\"" + "value=\"" + translatedText + "\"></td>" +
"<td><p style=\"font-size: 12px !important;\">Last Translated: " + lastMod + " by " + initials + "</p></td>" +
"</tr>";
}
counter++;
}
}
catch (Exception ex)
{
ex.Message.ToString();
}
}
}
//this is where I pass in variables to paging link function
pagingLinks = CreatePagingLinks(int.Parse(pageNumber), matchCount, "default.aspx?", 10);
My paging links are created like this:
string pagingInfo= "";
int rangeFrom = rowsPerPage * (currentPage - 1) + 1;
int rangeTo = rangeFrom + rowsPerPage - 1;
int maxpages = (matches / rowsPerPage) + 1;
if (currentPage == 1)
{
pagingInfo += "Prev | ";
} else
{
pagingInfo += "<a href=\"" + baseURL + "page=" + (currentPage - 1).ToString() + "\">Prev</a> | ";
}
for (int k = 1; k <= maxpages; k++)
{
pagingInfo += " <a href=\"" + baseURL + "page=" + k.ToString() + "\">" + k.ToString() + "</a> ";
}
if (currentPage == maxpages)
{
pagingInfo += " | Next";
}
else
{
pagingInfo += " | <a href=\"" + baseURL + "\">Next</a>";
}
return pagingInfo;
I see my problem is that my filters are not persisting through the pageloads...but I'm not sure how and where to fix it. Any help would be appreciated thank you!!