• GridView中使用DropDownList的OnSelectedIndexChanged事件


    今天遇到了在GridView中使用DropDownList的OnSelectedIndexChanged事件。在此小结下,方便博友们参考哈。

    前台代码:

    <asp:TemplateField HeaderText="分值" 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>


    后台OnSelectedIndexChanged事件:

    /// <summary>
        /// 评分
        /// </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;//获得GridView1中的DropDownList1控件
    
            //也可以这样写 
            //GridViewRow row = (GridViewRow)ddl.Parent.Parent;
            //GridViewRow row1 = (GridViewRow)ddl.NamingContainer;//通过ddl控件找到所在的行
            //int aa = Convert.ToInt32(row1.RowIndex.ToString());//获得行的rowindex
            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();//获得选择的值
                model.DF_Flag = 1;//表示打分标识
                model.DF_Date = DateTime.Now.ToShortDateString();
                model.Up_DF_Date = DateTime.Now.ToShortDateString();
                bll.Update_MIS_GradeInfo(model);
            }
            
    
        }
  • 相关阅读:
    oracle 批量修改表名 字段为大写197
    身份证附件上传样例197
    npm 设置源197
    manajo常用命令197
    vue 父组件向子组件传参197
    将BAT文件注册为服务197
    teaweb — linux 系统资源监控
    glances — linux 系统资源监控
    emitter-Client
    urlencode编码 — 为什么要编码
  • 原文地址:https://www.cnblogs.com/for917157ever/p/3082790.html
Copyright © 2020-2023  润新知