I Want to provide Navigate Facillities using DataSet in Asp.net. When we click on Next Button it should be displayed Next Record values in Textboxes. The Following code not working correctly. What is the problem in this? But it is working in WindowsForrms?
public partial class RoI2Test : System.Web.UI.Page
{
SqlConnection con=new SqlConnection("user id=sa;password=hari;database=emp;server=.");
SqlDataAdapter da;
DataSet ds;
int r;
protected void Page_Load(object sender, EventArgs e)
{
string s="select * from Products";
da = new SqlDataAdapter(s, con);
ds = new DataSet();
da.Fill(ds, "x");
}
public void getdata()
{
txtPName.Text = ds.Tables[0].Rows[r][0].ToString();
txtPrice.Text = ds.Tables[0].Rows[r][1].ToString();
txtStatus.Text = ds.Tables[0].Rows[r][2].ToString();
lblDisplay.Text = (r + 1) + " Th row of" + ds.Tables[0].Rows.Count;
}
protected void btnPrevious_Click(object sender, EventArgs e)
{
if (r == 0)
lblDisplay.Text = "This is First Row";
else
{
r = r - 1;
getdata();
}
}
protected void btnNext_Click(object sender, EventArgs e)
{
r = r + 1;
getdata();
}
}
Sra1