zoukankan      html  css  js  c++  java
  • 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);
            }
            
    
        }
  • 相关阅读:
    解决Struts中文乱码问题总结
    多校第十场1009 CRB and String题解
    DirectX--Filter属性页的调用
    理解ThreadLocal类
    unity3d
    使用Java8提供的Duration类制作字幕时间轴调整工具
    算法练习--卡片游戏
    在eclipse中创建web项目
    testNg官方文档
    TestNG基本注解(注释)
  • 原文地址:https://www.cnblogs.com/for917157ever/p/3082790.html
Copyright © 2011-2022 走看看