با سلام
ابتدا یه واریبل تعریف می کنی اینطوری
DataTable dt = new DataTable();
static int rowIndex = 0;
برای قسمت لود فرم می نویس
objClsVariables.objDataSet = new DataSet();
objClsVariables.objDataSet = objClsDBTask.ExecuteDataset("SELECT * FROM AddQuestionPaper WHERE QuePaperTypeId =" + iquestionpaperid1 + " AND SubjectId="+isubjectid1+" AND Language='"+ strlanguage +"'");
dataGridView1.DataSource = objClsVariables.objDataSet.Tables[0];
dt = new DataTable();
dt = objClsVariables.objDataSet.Tables[0];
if (dt.Rows.Count > 0)
{
if (rowIndex==0)
{
lblQue.Text = dt.Rows[rowIndex][5].ToString();
radioButton1.Text = dt.Rows[rowIndex][7].ToString();
radioButton2.Text = dt.Rows[rowIndex][8].ToString();
radioButton3.Text = dt.Rows[rowIndex][9].ToString();
radioButton4.Text = dt.Rows[rowIndex][10].ToString();
lblQueNo.Text = Convert.ToString(1)+" :-";
}
بعد می آیی برا هر کدوم از دکمه ها کد می نویسی که اینطوری می شه
دکمه ابتدا :
private void btnFirst_Click(object sender, EventArgs e)
{
try
{
if (rowIndex != -1)
{
rowIndex = 0;
lblQueNo.Text = Convert.ToString(rowIndex+1) + " :-";
lblQue.Text = dt.Rows[rowIndex][5].ToString();
radioButton1.Text = dt.Rows[rowIndex][7].ToString();
radioButton2.Text = dt.Rows[rowIndex][8].ToString();
radioButton3.Text = dt.Rows[rowIndex][9].ToString();
radioButton4.Text = dt.Rows[rowIndex][10].ToString();
}
else
{
MessageBox.Show("No more question is availabe!!!!!");
rowIndex = 0;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
دکمه انتها
private void btnNext_Click(object sender, EventArgs e)
{
try
{
if (rowIndex < dt.Rows.Count-1 )
{
if (rowIndex ==0)
{
rowIndex = 1;
lblQue.Text = dt.Rows[rowIndex][5].ToString();
radioButton1.Text = dt.Rows[rowIndex][7].ToString();
radioButton2.Text = dt.Rows[rowIndex][8].ToString();
radioButton3.Text = dt.Rows[rowIndex][9].ToString();
radioButton4.Text = dt.Rows[rowIndex][10].ToString();
lblQueNo.Text = Convert.ToString(rowIndex+1)+" :-";
}
else
{
rowIndex = rowIndex + 1;
lblQue.Text = dt.Rows[rowIndex][5].ToString();
radioButton1.Text = dt.Rows[rowIndex][7].ToString();
radioButton2.Text = dt.Rows[rowIndex][8].ToString();
radioButton3.Text = dt.Rows[rowIndex][9].ToString();
radioButton4.Text = dt.Rows[rowIndex][10].ToString();
lblQueNo.Text = Convert.ToString(rowIndex+1)+" :-";
}
}
else
{
MessageBox.Show("No more question is availabe!!!!!");
rowIndex = dt.Rows.Count - 1;
}
}
catch (Exception ex )
{
MessageBox.Show(ex.ToString());
}
}
برای دکمه " قبلی " یعنی یه فیلد قبل
private void btnNext_Click(object sender, EventArgs e)
{
try
{
if (rowIndex < dt.Rows.Count-1 )
{
if (rowIndex ==0)
{
rowIndex = 1;
lblQue.Text = dt.Rows[rowIndex][5].ToString();
radioButton1.Text = dt.Rows[rowIndex][7].ToString();
radioButton2.Text = dt.Rows[rowIndex][8].ToString();
radioButton3.Text = dt.Rows[rowIndex][9].ToString();
radioButton4.Text = dt.Rows[rowIndex][10].ToString();
lblQueNo.Text = Convert.ToString(rowIndex+1)+" :-";
}
else
{
rowIndex = rowIndex + 1;
lblQue.Text = dt.Rows[rowIndex][5].ToString();
radioButton1.Text = dt.Rows[rowIndex][7].ToString();
radioButton2.Text = dt.Rows[rowIndex][8].ToString();
radioButton3.Text = dt.Rows[rowIndex][9].ToString();
radioButton4.Text = dt.Rows[rowIndex][10].ToString();
lblQueNo.Text = Convert.ToString(rowIndex+1)+" :-";
}
}
else
{
MessageBox.Show("No more question is availabe!!!!!");
rowIndex = dt.Rows.Count - 1;
}
}
catch (Exception ex )
{
MessageBox.Show(ex.ToString());
}
}
این کد هم برای دکمه رفتن به اتتها
private void btnLast_Click(object sender, EventArgs e)
{
try
{
if (rowIndex != -1 && dt.Rows.Count > rowIndex )
{
rowIndex = dt.Rows.Count-1;
lblQueNo.Text = Convert.ToString(rowIndex + 1) + " :-";
lblQue.Text = dt.Rows[rowIndex][5].ToString();
radioButton1.Text = dt.Rows[rowIndex][7].ToString();
radioButton2.Text = dt.Rows[rowIndex][8].ToString();
radioButton3.Text = dt.Rows[rowIndex][9].ToString();
radioButton4.Text = dt.Rows[rowIndex][10].ToString();
}
else
{
MessageBox.Show("No more question is availabe!!!!!");
rowIndex = 0;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}