Click here to Skip to main content
14,268,096 members
Rate this:
Please Sign up or sign in to vote.
See more:
I tried to filter a row selection from gridview1 into gridview2, however the output in gridview2 is the listing of the table without any filter.

The codes are as follows



///
            ///
            ///GRIDVIEW2
            ///
            ///

            string str1;
            str1 = ConfigurationManager.ConnectionStrings["WEBHR"].ConnectionString;
            SqlConnection sqlcon1 = new SqlConnection(str1);

            string intno7, intno8;

            //Get the intno
           // intno7 = GridView2.SelectedRow.Cells[2].Text;
           // intno8 = GridView2.SelectedRow.Cells[6].Text;

            intno7 = txt_Code.Text;
            intno8 = txt_Year.Text;

            //call the stored procedure
            SqlCommand SqlCmd1 = new SqlCommand("sp_GetLeavGrid2year", sqlcon1);
            SqlCmd1.CommandType = System.Data.CommandType.StoredProcedure;


            //Supply the User_id parameter
            SqlCmd1.Parameters.AddWithValue("@BRNNO", intno7);
            SqlCmd1.Parameters.AddWithValue("@BYEAR", intno8);



            //Create and supply the output parameters

            //Create and supply the output parameters
            SqlCmd1.Parameters.Add("@BEMPNO", System.Data.SqlDbType.VarChar, 50);
            SqlCmd1.Parameters["@BEMPNO"].Direction = System.Data.ParameterDirection.Output;



            SqlCmd1.Parameters.Add("@BRETURNDATE", System.Data.SqlDbType.VarChar, 50);
            SqlCmd1.Parameters["@BRETURNDATE"].Direction = System.Data.ParameterDirection.Output;

            SqlCmd1.Parameters.Add("@BIDCNT", System.Data.SqlDbType.VarChar, 50);
            SqlCmd1.Parameters["@BIDCNT"].Direction = System.Data.ParameterDirection.Output;


            //Open the sql data connection
            sqlcon1.Open();

            //Execute the stored procedures
            SqlCmd1.ExecuteNonQuery();

            //Assign the results to the controls

            txt_idcnt.Text = SqlCmd1.Parameters["@BIDCNT"].Value.ToString();
            txt_Code.Text = SqlCmd1.Parameters["@BRNNO"].Value.ToString();
            txt_Empno.Text = SqlCmd1.Parameters["@BEMPNO"].Value.ToString();

            txt_Return_Date.Text = SqlCmd1.Parameters["@BRETURNDATE"].Value.ToString();
            txt_Year.Text = SqlCmd1.Parameters["@BYEAR"].Value.ToString();


            //SqlDataAdapter dm = new SqlDataAdapter("Select * from curasch where idno=@BRNNO and year1=@BYEAR", sqlcon1);

            SqlDataAdapter dm = new SqlDataAdapter("Select * from curasch where idno='" + txt_Code.Text + "' and year1='" + txt_Year.Text + "'", sqlcon1);

            DataSet df = new DataSet();
            dm.Fill(df,"Curasch");

            GridView2.DataSource = df.Tables[0];
            GridView2.DataBind();

            //GridView2.SelectedIndexChanged += new EventHandler(GridView2_SelectedIndexChanged);

            txt_Empno.Focus();

            LoadTransactionSearch();

            lblstatus.Text = "///Grid2 record successful";



            //  txt_Ed_Date.Text = SqlCmd.Parameters["@BEDDATE"].Value.ToString();

            lblstatus.Text = "///Grid2View record successful";

            //
            //
            sqlcon1.Close();




            ///
            ///
            ///GRIDVIEW2
            ///
            ///



Because the filter wasn't working I tried an alternative, however the filter is still not working.

Please assist me to rectify this issue.

Thanks

What I have tried:

I have checked the net for similar example, however i couldn't find any.
Posted
Comments
CHill60 14-Mar-17 7:37am
   
Do not use string concatenation to create your sql statement - use SqlParameters
sachin.vishwa90 14-Mar-17 8:21am
   
did you check if you are getting value from first gridview? is your ADO code returning you proper data?
And it is preferable to use updatepanel for such scenarios. other wise changes will happen and pageload event will reset the things again, due to which you will not see the new changes.
Member 12770648 14-Mar-17 9:12am
   
please assist with the updatepanel, not familiar with that

thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month



CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100