Click here to Skip to main content
15,902,777 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all
i am trying to navigate to the next record using textbox but could not figure out that how can i store row index some where in form
any help will be deeply appreciated
here is what i am trying
C#
protected void btn_next_Click(object sender, EventArgs e)
   {
       string strcon = ConfigurationManager.ConnectionStrings["gallup"].ConnectionString;
       string next = "SELECT * from city_breakup";
       SqlDataAdapter dauniq = new SqlDataAdapter(next, strcon);
       DataTable tableuniq = new DataTable();
       dauniq.Fill(tableuniq);
       int i=0;
       if(i<tableuniq.Rows.Count-1){
           txtlcity.Text=tableuniq.Rows[i]["city"].ToString();
           txtsample.Text = tableuniq.Rows[i]["sample"].ToString();
       }
   }
Posted

You should not get the data on this click event. You may do it in form load event. Declare the index variable (in your code its "i"), SqlDataAdapter, DataTable at module level and increase it with every click of "Next" button.
 
Share this answer
 
Comments
mehdilahori 19-Jul-12 1:38am    
can u come up with an example
you can use session for this purpose

C#
if(i<tableuniq.Rows.Count-1){
            if (session["Rowindex"]==null) session["Rowindex"]=i;
            txtlcity.Text=tableuniq.Rows[session["Rowindex"]]["city"].ToString();
            txtsample.Text = tableuniq.Rows[session["Rowindex"]]["sample"].ToString();
session["Rowindex"]=i+1;
        }
 
Share this answer
 

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