Click here to Skip to main content
15,888,303 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more: , +
Hi All,

Wish to all happy new year 2012....... :)

I am using vs2008, C#.net, SqlServer 2005.

How to navigate data on button click in window form using c#.net, i want to access data in next button and previous button.


plz give me suggestion ......
help will be appreciated.............

mukesh
Posted
Updated 8-Jan-12 18:48pm
v3
Comments
Sergey Alexandrovich Kryukov 9-Jan-12 0:24am    
Not clear what exactly do you want to achieve, what's your problem.
--SA

How to: Navigate Data in Windows Forms[^] is possibly just what you are looking for.
 
Share this answer
 
Great attempt, however you need to seperate the control.text assignments into another method. Also your logic is off so you should look at http://www.homeandlearn.co.uk/csharp/csharp_s12p8.html[^]

Best Wishes
 
Share this answer
 
Hi,

Navigate data on button click in window form using c#.net.
Navigation data on First button,Next button,previous button and Last button.

C#
//Declare variables...................

 DataTable dt = new DataTable();
 static int rowIndex = 0;


C#
//code on Form_load()....................

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)+" :-";
                         }


C#
// First button click...................
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());
            }
        }



C#
//Next button click........................
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());
            }

        }



C#
//Previous button click......................................
private void btnPrevious_Click(object sender, EventArgs e)
        {

            try
            {
                if (rowIndex < dt.Rows.Count  )
                {
                    if (rowIndex == dt.Rows.Count-1)
                    {

                        lblQueNo.Text = Convert.ToString(rowIndex)+" :-";
                        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();

                    }
                    else
                    {
                        if (rowIndex != 0)
                        {
                            lblQueNo.Text = Convert.ToString(rowIndex) +" :-";
                            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();

                        }
                        else
                        {
                            MessageBox.Show("No more question is availabe!!!!!");
                            rowIndex = 0;
                        }
                    }

                }
                else
                {
                    MessageBox.Show("No more question is availabe!!!!!");
                    rowIndex = 0;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

        }


C#
//Last button click.........................
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());
            }
        }



Try this it code will up holpful.................
Mukesh
 
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