Today, we encountered the onselectedindexchanged event using dropdownlist in the gridview. In this summary, it is convenient for Boyou to refer.
Front-endCode:
<Asp: templatefield headertext = " Score " Itemstyle-horizontalalign = " Center " > <Itemtemplate> <asp: dropdownlist id = " Gradelist " Runat = " Server " Width = " 100px " Onselectedindexchanged = " Dd_selectedindexchanged " Autopostback = " True " > <Asp: listitem> </ASP: listitem> <asp: listitem> 0 </ASP: listitem> <asp: listitem> 10 </ASP: listitem> <asp: listitem> 20 </ASP: listitem> <asp: listitem> 30 </ASP: listitem> <asp: listitem> 40 </ASP: listitem> <asp: listitem> 50 </ASP: listitem> <asp: listitem> 60 </ASP: listitem> <asp: listitem>70 </ASP: listitem> <asp: listitem> 80 </ASP: listitem> <asp: listitem> 90 </ASP: listitem> <asp: listitem> 100 </ASP: listitem> </ASP: dropdownlist> </itemtemplate> </ASP: templatefield>
Background onselectedindexchanged event:
/// <Summary> /// Rating /// </Summary> /// <Param name = "sender"> </param> /// <Param name = "E"> </param> Protected Void Dd_selectedindexchanged ( Object Sender, eventargs e) {gridviewrow gvr = (Gridviewrow) (Control) sender). Parent. parent; dropdownlist DDL = (Dropdownlist) sender; // Obtain the dropdownlist1 control in gridview1. // You can also write it like this. // Gridviewrow ROW = (gridviewrow) DDL. Parent. parent; // Gridviewrow row1 = (gridviewrow) DDL. namingcontainer; // Use the DDL control to find the row // Int AA = convert. toint32 (row1.rowindex. tostring ()); // Obtain rowindex of a row Querybuilder QB = New Querybuilder (); QB. addfilter ( " Mis_gradeinfo.sf_userid " , Webcommon. SQL _equal, gvr. cells [ 0 ]. Text); QB. addfilter ( " Mis_gradeinfo.df_week " , Webcommon. SQL _equal, gvr. cells [ 2 ]. Text); ilist <Mis_gradeinfomodel> mis_gradeinfomodel = Bll. getmis_gradeinfomodelbycondition (QB ); If (Mis_gradeinfomodel.count> 0 ) {Model = Mis_gradeinfomodel [ 0 ]; Model. df_userid = Usernum. value; model. df_username = Username. Text; model. gradenum = DDL. selectedvalue. tostring (); // Obtain the selected value Model. df_flag = 1 ; // Indicates the score ID. Model. df_date = Datetime. Now. to1_datestring (); Model. up_df_date = Datetime. Now. tow.datestring (); BLL. update_mis_gradeinfo (model );}}