Click here to Skip to main content
15,886,835 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi, i have .aspx and aspx.cs file. In .aspx i have asp:GridView. In aspx.cs file, i have a method getCheckedProduct, where i get checked values
C#
private void getCheckedProduct()
{
   if (selected == string.Empty)
   {
      selected = Request.Form["selectProductName"];
   }
   else if (selected != string.Empty && Request.Form["selectProductName"] != string.Empty)
   {
      selected = selected + "," + Request.Form["selectProductName"];
   }
}


When i change the GridView page from 1 to 2 and back from 2 to 1, if statement ("&& Request.Form["selectProductName"] != string.Empty)") in getCheckedProduct() method does not detect tis... in the variable "selected" is added ",". Why?
Posted
Updated 13-May-14 0:27am
v3

1 solution

put a static string in your page and get that value before postback
Then no need to call this method again after your gridview pagination
static string selected = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            getCheckedProduct();
        }
    } 


In pagination time just call the string selected and use it with your requirements
 
Share this answer
 
Comments
vezo11 13-May-14 7:37am    
Hi,
thanks for your solution but i have static string "selected".

"getCheckedProduct();" i call in "..._SelectedIndexChanged()" and if i add !IsPostBack in this method, then program skipped this call ("getCheckedProduct();")
[no name] 13-May-14 7:44am    
But for the first of page it will call then no need to call again it
You will get the value from your static string

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900