c# - Edit Not Working After GridView Filter By Drop Down -


i stuck @ editing editing point after filtering gridview drop down list(i.e dropdown placed outside gridview). when click on editlink after filtering gridview makes starting rows of whole grid editable. want in asp.net instead of j-query or ajax.! 1 , please me on this??? here code:`

        protected void fillgrid()     {         //string studentsectionid = convert.tostring(ddlsectionid.selectedvalue);         sqlconnection con = new sqlconnection(configurationmanager.connectionstrings["final year project"].tostring());         con.open();         string query = "  select st.studentid, studentno, studentpassword, studentname, cl.studentclassname, cl.studentclassid,se.studentsectionid,ge.studentgenderid,gu.studentguardianid,tr.studenttransportid,se.studentsectionname, studentrollno, studentsession, ge.studentgendername, studentphone,studentaddress, studentemail, gu.studentguardianname, studentreligion,tr.studenttransportrouteno, studentdob,studentfees student st inner join class cl on st.studentclassid = cl.studentclassid inner join section se on st.studentsectionid = se.studentsectionid inner join gender ge on ge.studentgenderid = st.studentgenderid inner join guardian gu on gu.studentguardianid = st.studentguardianid inner join transport tr on tr.studenttransportid = st.studenttransportid";         sqlcommand cmd = new sqlcommand(query, con);         sqldataadapter da = new sqldataadapter(cmd);         dataset ds = new dataset();         da.fill(ds);         con.close();         gv_student.datasource = ds;         gv_student.databind();     } protected void ddlsectionid_selectedindexchanged(object sender, eventargs e)     {         string studentsectionname = convert.tostring(ddlsectionid.selecteditem);         sqlconnection oconn = new sqlconnection(configurationmanager.connectionstrings["final year project"].tostring());         oconn.open();         sqlcommand ocmd = new sqlcommand("select st.studentid,studentno,studentpassword, studentname, cl.studentclassname, se.studentsectionname,se.studentsectionid, studentrollno, studentsession, ge.studentgendername, studentphone, studentaddress, studentemail, gu.studentguardianname, studentreligion, tr.studenttransportrouteno, studentdob,studentfees student st inner join class cl on st.studentclassid = cl.studentclassid inner join section se on st.studentsectionid = se.studentsectionid inner join gender ge on ge.studentgenderid = st.studentgenderid inner join guardian gu on gu.studentguardianid = st.studentguardianid inner join transport tr on tr.studenttransportid = st.studenttransportid se.studentsectionname='"+studentsectionname+"'", oconn);         sqldataadapter oda = new sqldataadapter(ocmd);         sqlcommandbuilder builder = new sqlcommandbuilder(oda);         dataset ds = new dataset();         oda.fill(ds);         gv_student.datasource = ds;         gv_student.databind();     }     protected void gv_student_rowdatabound(object sender, gridviewroweventargs e)     {         if (e.row.rowtype == datacontrolrowtype.datarow)         {             if ((e.row.rowstate & datacontrolrowstate.edit) > 0)             {                 dropdownlist ddlclassid = (dropdownlist)e.row.findcontrol("ddlclassid");                 datatable dt;                 string sql = "select * class";                  string sconstr = configurationmanager.connectionstrings["final year project"].connectionstring;                 using (sqlconnection conn = new sqlconnection(sconstr))                 {                     using (sqlcommand comm = new sqlcommand(sql, conn))                     {                         conn.open();                         using (sqldataadapter da = new sqldataadapter(comm))                         {                             dt = new datatable("tbl");                             da.fill(dt);                         }                     }                 }                 ddlclassid.datasource = dt;                 ddlclassid.datatextfield = "studentclassname";                 ddlclassid.datavaluefield = "studentclassid";                 ddlclassid.databind();                 ddlclassid.selectedvalue = ((datarowview)e.row.dataitem)["studentclassid"].tostring();             }         }          // section         if (e.row.rowtype == datacontrolrowtype.datarow)         {             if ((e.row.rowstate & datacontrolrowstate.edit) > 0)             {                  dropdownlist ddlsectionid = (dropdownlist)e.row.findcontrol("ddlsectionid");                 datatable dt1;                 string sql1 = "select * section";                  string sconstr1 = configurationmanager.connectionstrings["final year project"].connectionstring;                 using (sqlconnection conn = new sqlconnection(sconstr1))                 {                     using (sqlcommand comm = new sqlcommand(sql1, conn))                     {                         conn.open();                         using (sqldataadapter da = new sqldataadapter(comm))                         {                             dt1 = new datatable("tbl");                             da.fill(dt1);                         }                     }                 }                 ddlsectionid.datasource = dt1;                 ddlsectionid.datatextfield = "studentsectionname";                 ddlsectionid.datavaluefield = "studentsectionid";                 ddlsectionid.databind();                 ddlsectionid.selectedvalue = ((datarowview)e.row.dataitem)["studentsectionid"].tostring();             }         }          //for gender         if (e.row.rowtype == datacontrolrowtype.datarow)         {             if ((e.row.rowstate & datacontrolrowstate.edit) > 0)             {                  dropdownlist ddlgenderid = (dropdownlist)e.row.findcontrol("ddlgenderid");                 datatable dt2;                 string sql2 = "select * gender";                  string sconstr1 = configurationmanager.connectionstrings["final year project"].connectionstring;                 using (sqlconnection conn = new sqlconnection(sconstr1))                 {                     using (sqlcommand comm = new sqlcommand(sql2, conn))                     {                         conn.open();                         using (sqldataadapter da = new sqldataadapter(comm))                         {                             dt2 = new datatable("tbl");                             da.fill(dt2);                         }                     }                 }                 ddlgenderid.datasource = dt2;                 ddlgenderid.datatextfield = "studentgendername";                 ddlgenderid.datavaluefield = "studentgenderid";                 ddlgenderid.databind();                 ddlgenderid.selectedvalue = ((datarowview)e.row.dataitem)["studentgenderid"].tostring();             }         }          //for guardian         if (e.row.rowtype == datacontrolrowtype.datarow)         {             if ((e.row.rowstate & datacontrolrowstate.edit) > 0)             {                  dropdownlist ddlguardianid = (dropdownlist)e.row.findcontrol("ddlguardianid");                 datatable dt3;                 string sql3 = "select * guardian";                  string sconstr1 = configurationmanager.connectionstrings["final year project"].connectionstring;                 using (sqlconnection conn = new sqlconnection(sconstr1))                 {                     using (sqlcommand comm = new sqlcommand(sql3, conn))                     {                         conn.open();                         using (sqldataadapter da = new sqldataadapter(comm))                         {                             dt3 = new datatable("tbl");                             da.fill(dt3);                         }                     }                 }                 ddlguardianid.datasource = dt3;                 ddlguardianid.datatextfield = "studentguardianname";                 ddlguardianid.datavaluefield = "studentguardianid";                 ddlguardianid.databind();                 ddlguardianid.selectedvalue = ((datarowview)e.row.dataitem)["studentguardianid"].tostring();             }         }          //for transport         if (e.row.rowtype == datacontrolrowtype.datarow)         {             if ((e.row.rowstate & datacontrolrowstate.edit) > 0)             {                  dropdownlist ddltransportid = (dropdownlist)e.row.findcontrol("ddltransportid");                 datatable dt4;                 string sql4 = "select * transport";                  string sconstr1 = configurationmanager.connectionstrings["final year project"].connectionstring;                 using (sqlconnection conn = new sqlconnection(sconstr1))                 {                     using (sqlcommand comm = new sqlcommand(sql4, conn))                     {                         conn.open();                         using (sqldataadapter da = new sqldataadapter(comm))                         {                             dt4 = new datatable("tbl");                             da.fill(dt4);                         }                     }                 }                 ddltransportid.datasource = dt4;                 ddltransportid.datatextfield = "studenttransportrouteno";                 ddltransportid.datavaluefield = "studenttransportid";                 ddltransportid.databind();                 ddltransportid.selectedvalue = ((datarowview)e.row.dataitem)["studenttransportid"].tostring();             }         }      }     protected void gv_student_rowdeleting(object sender, gridviewdeleteeventargs e)     {         int studentid = convert.toint32(gv_student.datakeys[e.rowindex].value);         sqlconnection oconn = new sqlconnection(configurationmanager.connectionstrings["final year project"].tostring());         oconn.open();         sqlcommand ocmd = new sqlcommand();         ocmd.commandtext = "delete student studentid=@studentid";         ocmd.parameters.addwithvalue("@studentid", studentid);         ocmd.connection = oconn;         ocmd.executenonquery();         oconn.close();         fillgrid();     }     protected void gv_student_rowediting(object sender, gridviewediteventargs e)     {         gv_student.editindex = e.neweditindex;             fillgrid();     }     protected void gv_student_rowupdating(object sender, gridviewupdateeventargs e)     {         int studentid = int.parse(((label)(gv_student.rows[e.rowindex].cells[1].findcontrol("lbl_id"))).text);         string studentno = ((textbox)(gv_student.rows[e.rowindex].cells[1].findcontrol("txtno"))).text;         string studentpassword = ((textbox)(gv_student.rows[e.rowindex].cells[1].findcontrol("txtpassword"))).text;         string studentname = ((textbox)(gv_student.rows[e.rowindex].cells[1].findcontrol("txtname"))).text;         string studentrollno = ((textbox)(gv_student.rows[e.rowindex].cells[1].findcontrol("txtrollno"))).text;         string studentsession = ((textbox)(gv_student.rows[e.rowindex].cells[1].findcontrol("txtsession"))).text;         string studentphone = ((textbox)(gv_student.rows[e.rowindex].cells[1].findcontrol("txtphone"))).text;         string studentaddress = ((textbox)(gv_student.rows[e.rowindex].cells[1].findcontrol("txtaddress"))).text;         string studentemail = ((textbox)(gv_student.rows[e.rowindex].cells[1].findcontrol("txtemail"))).text;         string studentreligion = ((textbox)(gv_student.rows[e.rowindex].cells[1].findcontrol("txtreligion"))).text;         string studentdob = ((textbox)(gv_student.rows[e.rowindex].cells[1].findcontrol("txtdob"))).text;         string studentfees = ((textbox)(gv_student.rows[e.rowindex].cells[1].findcontrol("txtfees"))).text;          int studentclassid = int.parse(((dropdownlist)(gv_student.rows[e.rowindex].cells[1].findcontrol("ddlclassid"))).selectedvalue);         int studentsectionid = int.parse(((dropdownlist)(gv_student.rows[e.rowindex].findcontrol("ddlsectionid"))).selectedvalue);         int studentgenderid = int.parse(((dropdownlist)(gv_student.rows[e.rowindex].cells[1].findcontrol("ddlgenderid"))).selectedvalue);         int studentguardianid = int.parse(((dropdownlist)(gv_student.rows[e.rowindex].cells[1].findcontrol("ddlguardianid"))).selectedvalue);         int studenttransportid = int.parse(((dropdownlist)(gv_student.rows[e.rowindex].cells[1].findcontrol("ddltransportid"))).selectedvalue);         sqlconnection oconn = new sqlconnection(configurationmanager.connectionstrings["final year project"].tostring());         oconn.open();         sqlcommand ocmd = new sqlcommand();         ocmd.commandtext = "update student set studentno=@studentno, studentpassword=@studentpassword, studentname=@studentname,studentrollno=@studentrollno,studentsession=@studentsession,studentphone=@studentphone,studentaddress=@studentaddress,studentemail=@studentemail,studentreligion=@studentreligion,studentdob=@studentdob,studentfees=@studentfees,studenttransportid=@studenttransportid,studentguardianid=@studentguardianid,studentgenderid=@studentgenderid,studentsectionid=@studentsectionid,studentclassid=@studentclassid studentid=@studentid";         ocmd.parameters.addwithvalue("@studentid", studentid);          ocmd.parameters.addwithvalue("@studentclassid", studentclassid);         ocmd.parameters.addwithvalue("@studentsectionid", studentsectionid);         ocmd.parameters.addwithvalue("@studentgenderid", studentgenderid);         ocmd.parameters.addwithvalue("@studentguardianid", studentguardianid);         ocmd.parameters.addwithvalue("@studenttransportid", studenttransportid);          ocmd.parameters.addwithvalue("@studentfees", studentfees);         ocmd.parameters.addwithvalue("@studentdob", studentdob);         ocmd.parameters.addwithvalue("@studentreligion", studentreligion);         ocmd.parameters.addwithvalue("@studentemail", studentemail);         ocmd.parameters.addwithvalue("@studentaddress", studentaddress);         ocmd.parameters.addwithvalue("@studentphone", studentphone);         ocmd.parameters.addwithvalue("@studentsession", studentsession);         ocmd.parameters.addwithvalue("@studentrollno", studentrollno);         ocmd.parameters.addwithvalue("@studentname", studentname);         ocmd.parameters.addwithvalue("@studentpassword", studentpassword);         ocmd.parameters.addwithvalue("@studentno", studentno);         ocmd.connection = oconn;         ocmd.executenonquery();         gv_student.editindex = -1;         fillgrid();         oconn.close();     }     protected void gv_student_rowcancelingedit(object sender, gridviewcancelediteventargs e)     {         gv_student.editindex = -1;         fillgrid();     } 


Comments