Click here to Skip to main content
15,888,195 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have created a search category function. which work fine

after that When i click Edit button it goes to first row of the gridview to edit the row

or if i click 2nd row from the search data i goes to 2nd row from gridview in edit mode.

Please help me.. i am not able to find the cause of this problem
C#
if (e.CommandName == "EditRow")
            {
                int rowIndex = ((GridViewRow)((LinkButton)e.CommandSource).NamingContainer).RowIndex;
                gvMainCategory.EditIndex = rowIndex;
                bindMC();
            }
//DataBinding method
        private void bindMC()
        {
            int counter = 1;
            counter = counter + 1;

            BL_MainCategory objBL_getMC = new BL_MainCategory();
            gvMainCategory.DataSource = objBL_getMC.LoadCategory();
            gvMainCategory.DataBind();
        }
private DataSet ExecuteSelectSQL(string sqlcmd)
        {
            string CS = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
            using (SqlConnection con = new SqlConnection(CS))
            {
                SqlDataAdapter da = new SqlDataAdapter(sqlcmd, con);
                DataSet ds = new DataSet();
                da.Fill(ds);
                return ds;
                
            }
        }

        public DataSet LoadMainCategory()
        {

            DataSet ds = new DataSet();
            string sql = "select * from MainCategory";
            ds = ExecuteSelectSQL(sql);
            return ds;
        }


I try to debug the edit method after filtering.

I came to know that the gridveiw edit index is setting to -1.

i think this the problem
Posted
Updated 15-Jan-16 19:13pm
v2
Comments
Show me the Page Load code.

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