如何移动下一个和上一个记录? [英] How to move a next and previous record?
本文介绍了如何移动下一个和上一个记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
public partial class Default2 : System.Web.UI.Page
{
#region
SqlConnection sc = new SqlConnection(ConfigurationManager.ConnectionStrings["ad"].ConnectionString);
DataSet ds;
int Maxrow=0;
int inc =0;
#endregion
protected void Page_Load(object sender, EventArgs e)
{
sc.Open();
ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter("select * from Customer", sc);
da.Fill(ds, "ad");
Navigate();
Maxrow = ds.Tables["ad"].Rows.Count;
}
private void Navigate()
{
DataRow drow = ds.Tables["ad"].Rows[inc];
TextBox1.Text = drow.ItemArray.GetValue(1).ToString();
TextBox2.Text = drow.ItemArray.GetValue(2).ToString();
}
protected void Next_Click(object sender, EventArgs e)
{
if (inc != Maxrow-1)
{
inc++;
Navigate();
}
else
{
MessageBox.Show("NoMore");
}
}
protected void Pre_click(object sender, EventArgs e)
{
if (inc > 0)
{
inc--;
Navigate();
}
//else
//{
// MessageBox.Show("first ");
//}
}
protected void Last_click(object sender, EventArgs e)
{
if (inc != Maxrow - 1)
{
inc = Maxrow - 1;
Navigate();
}
}
protected void Button5_Click(object sender, EventArgs e)
{
if (inc != 0)
{
inc = 0;
Navigate();
}
}
}
在此下一个和上一个语句中,仅使用表的前两行.请在c#
In this next and previous statements only take first two rows of table. Please clear doubt in c#
推荐答案
//Next -
this.BindingContext[dt].Position += 1;
//Previous
this.BindingContext[dt].Position -= 1;
//First
this.BindingContext[dt].Position = 0;
//last
this.BindingContext[dt].Count = this.BindingContext[].Position -1;;
乍看之下...
On a first look...
protected void Next_Click(object sender, EventArgs e)
{
if (inc < Maxrow-1) //(inc != Maxrow-1) <-- your condition
{
//you can move to the next record until current record isn't last
}
protected void Pre_click(object sender, EventArgs e)
{
if (inc >0) //(inc <0) <-- your condition
{
//you can move to the previous record until current record isn't first
}
然后,您之前的检查应该是(inc> 0),不是吗?还告诉我您有多少行,Maxrow的值是什么?
Then for previous your check should be if (inc > 0) isn''t it? Also tell me how many rows you have what is the value of Maxrow?
这篇关于如何移动下一个和上一个记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文