用js遍历gridview的textbox 并验证行值是否大于某个值 并批量保存数据

 aspx 页面 首先绑定单位名称和编号,其他的用模板加textbox给textbox付属性值

 

<asp:GridView ID="GridView1" runat="server" onrowcreated="GridView1_RowCreated2" onrowdatabound="GridView1_RowDataBound"   
           >
                <Columns>
              <asp:TemplateField HeaderText="序号">
                        <ItemTemplate>
                        <%# (this.AspNetPager1.CurrentPageIndex - 1) * this.AspNetPager1.PageSize + Container.DataItemIndex + 1%>
                        </ItemTemplate>
                        <ItemStyle Wrap="True" /> 
                        <HeaderStyle Wrap="False" />   
                    </asp:TemplateField>
                   <asp:BoundField HeaderText="部门ID"  DataField="GroupID" />
                      <asp:BoundField HeaderText="部门"   DataField="G_CName" />
                      <asp:TemplateField   HeaderText="工作效率">
                        <ItemTemplate>
                      
                            <asp:TextBox ID="gzxl_Input"  Text="0.0"  Width="40px"  CssClass="text_input" runat="server"
                                οnblur="setClf()"></asp:TextBox>
                        </ItemTemplate>
                        <ItemStyle Wrap="True" /> 
                        <HeaderStyle Wrap="False" />   
                    </asp:TemplateField>
                     <asp:TemplateField HeaderText="大局意识"  >
                        <ItemTemplate>
                      
                            <asp:TextBox ID="djys_Input"      Text="0.0"     Width="40px" 
                                CssClass="text_input" runat="server" 
                                οnblur="setClf()"></asp:TextBox>
                        </ItemTemplate>
                        <ItemStyle Wrap="True" /> 
                        <HeaderStyle Wrap="False" />   
                    </asp:TemplateField>
                        <asp:TemplateField HeaderText="任务完成" >
                        <ItemTemplate>
                      
                            <asp:TextBox ID="rwwc_Input"  Text="0.0"   Width="40px"  CssClass="text_input"
                                runat="server" AutoPostBack="True" ontextchanged="rwwc_Input_TextChanged"></asp:TextBox>
                        </ItemTemplate>
                        <ItemStyle Wrap="True" /> 
                        <HeaderStyle Wrap="False" />   
                    </asp:TemplateField>
                       <asp:TemplateField HeaderText="团结协作"   >
                        <ItemTemplate>
                      
                            <asp:TextBox ID="tj_Input"  Text="0.0"  Width="40px"  CssClass="text_input"
                                runat="server" οnblur="setClf()"></asp:TextBox>
                        </ItemTemplate>
                        <ItemStyle Wrap="True" /> 
                        <HeaderStyle Wrap="False" />   
                    </asp:TemplateField>
                  
                          <asp:TemplateField HeaderText="民主意识"   >
                        <ItemTemplate>
                      
                            <asp:TextBox ID="mzys_Input"  Text="0.0"  Width="40px"  CssClass="text_input"
                                runat="server" οnblur="setClf()"></asp:TextBox>
                        </ItemTemplate>
                        <ItemStyle Wrap="True" /> 
                        <HeaderStyle Wrap="False" />   
                    </asp:TemplateField>
                             <asp:TemplateField HeaderText="单位形象"  >
                        <ItemTemplate>
                      
                            <asp:TextBox ID="dwxx_Input"  Text="0.0" Width="40px"  CssClass="text_input"
                                runat="server" οnblur="setClf()" ></asp:TextBox>
                        </ItemTemplate>
                        <ItemStyle Wrap="True" /> 
                        <HeaderStyle Wrap="False" />   
                    </asp:TemplateField>
                                <asp:TemplateField  HeaderText="管理绩效"   >
                        <ItemTemplate>
                      
                            <asp:TextBox ID="gljx_Input"  Text="0.0"  Width="40px"  CssClass="text_input"
                                runat="server" οnblur="setClf()"></asp:TextBox>
                        </ItemTemplate>
                        <ItemStyle Wrap="True" /> 
                        <HeaderStyle Wrap="False" />   
                    </asp:TemplateField>
                                    <asp:TemplateField  HeaderText="廉洁从业"   >
                        <ItemTemplate>
                      
                            <asp:TextBox ID="ljcy_Input"  Text="0.0"   Width="40px"   CssClass="text_input"
                                runat="server" οnblur="setClf()"></asp:TextBox>
                        </ItemTemplate>
                        <ItemStyle Wrap="True" /> 
                        <HeaderStyle Wrap="False" />   
                    </asp:TemplateField>
                  
                  
                </Columns>
            </asp:GridView>

效果图如下

js代码 写在最下面

 

 function setClf()
      {
            var table=document.getElementById("ctl00_PageBody_GridView1");
            var tr=table.getElementsByTagName("tr");
         
            var pattem=/^/d+(/./d+)?$/;
            for( i=1;i <tr.length;i++)
            {
                var sum1;
                var a2,a3,a4,a5,a6,a7,a8,a9;
                if(pattem.test(tr[i].getElementsByTagName("td")[2].getElementsByTagName("input")[0].value))
                    a2=parseFloat( tr[i].getElementsByTagName("td")[2].getElementsByTagName("input")[0].value );
                else
                    a2=0;
                if(pattem.test(tr[i].getElementsByTagName("td")[3].getElementsByTagName("input")[0].value))
                    a3=parseFloat( tr[i].getElementsByTagName("td")[3].getElementsByTagName("input")[0].value );
                else
                    a3=0;
                if(pattem.test(tr[i].getElementsByTagName("td")[4].getElementsByTagName("input")[0].value))
                    a4=parseFloat( tr[i].getElementsByTagName("td")[4].getElementsByTagName("input")[0].value );
                else
                    a4=0;
                if(pattem.test(tr[i].getElementsByTagName("td")[5].getElementsByTagName("input")[0].value))
                    a5=parseFloat( tr[i].getElementsByTagName("td")[5].getElementsByTagName("input")[0].value );
                else
                    a5=0;
                if(pattem.test(tr[i].getElementsByTagName("td")[6].getElementsByTagName("input")[0].value))
                    a6=parseFloat( tr[i].getElementsByTagName("td")[6].getElementsByTagName("input")[0].value );
                else
                    a6=0;   
                if(pattem.test(tr[i].getElementsByTagName("td")[7].getElementsByTagName("input")[0].value))
                  a7=parseFloat( tr[i].getElementsByTagName("td")[7].getElementsByTagName("input")[0].value );
                else
                   a7=0; 
                  
                if(pattem.test(tr[i].getElementsByTagName("td")[7].getElementsByTagName("input")[0].value))
                  a8=parseFloat( tr[i].getElementsByTagName("td")[7].getElementsByTagName("input")[0].value );
                else
                   a8=0; 
                  
                if(pattem.test(tr[i].getElementsByTagName("td")[7].getElementsByTagName("input")[0].value))
                  a9=parseFloat( tr[i].getElementsByTagName("td")[7].getElementsByTagName("input")[0].value );
                else
                   a9=0;   
            
             
               var sum1= a2+a3+a4+a5+a6+a7+a8+a9
                if(sum1>1)
                {
                  alert("请检查输入数据有误!总和不能大于1" ) 
                }
                else
                {
                   sum2=1-sum1 ;
                  tr[i].getElementsByTagName("td")[2].getElementsByTagName("input")[0].title="该单位已经评价"+sum1+"分,还可以评价"+sum2+"分";
                  tr[i].getElementsByTagName("td")[3].getElementsByTagName("input")[0].title="该单位已经评价"+sum1+"分,还可以评价"+sum2+"分";
                  tr[i].getElementsByTagName("td")[4].getElementsByTagName("input")[0].title="该单位已经评价"+sum1+"分,还可以评价"+sum2+"分";
                  tr[i].getElementsByTagName("td")[5].getElementsByTagName("input")[0].title="该单位已经评价"+sum1+"分,还可以评价"+sum2+"分";
                  tr[i].getElementsByTagName("td")[6].getElementsByTagName("input")[0].title="该单位已经评价"+sum1+"分,还可以评价"+sum2+"分";
                  tr[i].getElementsByTagName("td")[7].getElementsByTagName("input")[0].title="该单位已经评价"+sum1+"分,还可以评价"+sum2+"分";
                  tr[i].getElementsByTagName("td")[8].getElementsByTagName("input")[0].title="该单位已经评价"+sum1+"分,还可以评价"+sum2+"分";
                  tr[i].getElementsByTagName("td")[9].getElementsByTagName("input")[0].title="该单位已经评价"+sum1+"分,还可以评价"+sum2+"分";
                }
            }

 

提交数据页面 遍历gridview

 

    foreach (GridViewRow row in GridView1.Rows)
                //for (int i = 0; i < GridView1.Rows.Count; i++)
                {
                sys_T_Leader_EvaluateEntity ut = new sys_T_Leader_EvaluateEntity();
                ut.DataTable_Action_ = DataTable_Action.Insert;
                int GroupID_Value =Convert.ToInt32(row.Cells[1].Text.ToString());
                int tjYear_Value = (int)Common.sink(tjYear_Input.UniqueID, MethodType.Post, 10, 0, DataType.Int); 
                int tjr_Value = UserData.GetUserDate.UserID;
           
                double gzxl = (double)Common.sink(((TextBox)row.FindControl("gzxl_Input")).UniqueID, MethodType.Post, 53, 0, DataType.Double);
                Common.sinkCompare("工作效率", ((TextBox)row.FindControl("gzxl_Input")).Text, MethodType.Post, 1, 0, DataType.Double);

                double djys = (double)Common.sink(((TextBox)row.FindControl("djys_Input")).UniqueID, MethodType.Post, 53, 0, DataType.Double);
                Common.sinkCompare("大局意识", ((TextBox)row.FindControl("djys_Input")).Text, MethodType.Post, 1, 0, DataType.Double);

                double rwwc = (double)Common.sink(((TextBox)row.FindControl("rwwc_Input")).UniqueID, MethodType.Post, 53, 0, DataType.Double);
                Common.sinkCompare("任务完成", ((TextBox)row.FindControl("rwwc_Input")).Text, MethodType.Post, 1, 0, DataType.Double);

                double tj = (double)Common.sink(((TextBox)row.FindControl("tj_Input")).UniqueID, MethodType.Post, 53, 0, DataType.Double);
                Common.sinkCompare("团结协作", ((TextBox)row.FindControl("tj_Input")).Text, MethodType.Post, 1, 0, DataType.Double);

                double mzys = (double)Common.sink(((TextBox)row.FindControl("mzys_Input")).UniqueID, MethodType.Post, 53, 0, DataType.Double);
                Common.sinkCompare("民主意识", ((TextBox)row.FindControl("mzys_Input")).Text, MethodType.Post, 1, 0, DataType.Double);

                double dwxx = (double)Common.sink(((TextBox)row.FindControl("dwxx_Input")).UniqueID, MethodType.Post, 53, 0, DataType.Double);
                Common.sinkCompare("单位形象", ((TextBox)row.FindControl("dwxx_Input")).Text, MethodType.Post, 1, 0, DataType.Double);

                double gljx = (double)Common.sink(((TextBox)row.FindControl("gljx_Input")).UniqueID, MethodType.Post, 53, 0, DataType.Double);
                Common.sinkCompare("管理绩效", ((TextBox)row.FindControl("gljx_Input")).Text, MethodType.Post, 1, 0, DataType.Double);

                double ljcy = (double)Common.sink(((TextBox)row.FindControl("ljcy_Input")).UniqueID, MethodType.Post, 53, 0, DataType.Double);
                Common.sinkCompare("廉洁从业", ((TextBox)row.FindControl("ljcy_Input")).Text, MethodType.Post, 1, 0, DataType.Double);

                ut.GroupID = GroupID_Value;
                ut.tjYear = tjYear_Value;
                ut.niandu = niandu_Input.SelectedItem.Text;
                ut.gzxl = gzxl;
                ut.djys = djys;
                ut.rwwc = rwwc;
                ut.tj = tj;
                ut.mzys = mzys;
                ut.dwxx = dwxx;
                ut.gljx = gljx;
                ut.ljcy = ljcy;
                ut.tjr = tjr_Value; 
                BusinessFacadeModel.sys_T_Leader_EvaluateInsertUpdateDelete(ut);
               }

 

相关推荐
<p> <span style="font-size:14px;color:#E53333;">限时福利1:</span><span style="font-size:14px;">购课进答疑群专享柳峰(刘运强)老师答疑服务</span> </p> <p> <br /> </p> <p> <br /> </p> <p> <span style="font-size:14px;"></span> </p> <p> <span style="font-size:14px;color:#337FE5;"><strong>为什么需要掌握高性能MySQL实战?</strong></span> </p> <p> <span><span style="font-size:14px;"><br /> </span></span> <span style="font-size:14px;">由于互联网产品户量大、高发请求场景多,因此对MySQL性能、可性、扩展性都提出了很高要求。使MySQL解决大量数据以及高发请求已经是程序员必备技能,也是衡量一个程序员能力和薪资标准之一。</span> </p> <p> <br /> </p> <p> <span style="font-size:14px;">为了让大家快速系统了解高性能MySQL核心知识全貌,我为你总结了</span><span style="font-size:14px;">「高性能 MySQL 知识框架图」</span><span style="font-size:14px;">,帮你梳理学习重点,建议收藏!</span> </p> <p> <br /> </p> <p> <img alt="" src="https://img-bss.csdnimg.cn/202006031401338860.png" /> </p> <p> <br /> </p> <p> <span style="font-size:14px;color:#337FE5;"><strong>【课程设计】</strong></span> </p> <p> <span style="font-size:14px;"><br /> </span> </p> <p> <span style="font-size:14px;">课程分为四大篇章,将为你建立完整 MySQL 知识体系,同时将重点讲解 MySQL 底层运行原理、数据性能调优、高发、海量业务处理、面试解析等。</span> </p> <p> <span style="font-size:14px;"><br /> </span> </p> <p> <span style="font-size:14px;"></span> </p> <p style="text-align:justify;"> <span style="font-size:14px;"><strong>一、性能优化篇:</strong></span> </p> <p style="text-align:justify;"> <span style="font-size:14px;">主要包括经典 MySQL 问题剖析、索引底层原理和事务与锁机制。通过深入理解 MySQL 索引结构 B+Tree ,学员能够从根本上弄懂为什么有些 SQL 走索引、有些不走索引,从而彻底掌握索引使和优化技巧,能够避开很多实战中遇到“坑”。</span> </p> <p style="text-align:justify;"> <br /> </p> <p style="text-align:justify;"> <span style="font-size:14px;"><strong>二、MySQL 8.0新特性篇:</strong></span> </p> <p style="text-align:justify;"> <span style="font-size:14px;">主要包括窗口函数和通表表达式。企业中许多报表统计需求,如果不采窗口函数,普通 SQL 语句是很难实现。</span> </p> <p style="text-align:justify;"> <br /> </p> <p style="text-align:justify;"> <span style="font-size:14px;"><strong>三、高性能架构篇:</strong></span> </p> <p style="text-align:justify;"> <span style="font-size:14px;">主要包括主从复制和读写分离。在企业生产环境中,很少采单台MySQL节点情况,因为一旦单个节点发生故障,整个系统都不可,后果往往不堪设想,因此掌握高可架构实现是非常有必要。</span> </p> <p style="text-align:justify;"> <br /> </p> <p style="text-align:justify;"> <span style="font-size:14px;"><strong>四、面试篇:</strong></span> </p> <p style="text-align:justify;"> <span style="font-size:14px;">程序员获得工作第一步,就是高效准备面试,面试篇主要从知识点回顾总结角度出发,结合程序员面试高频MySQL问题精讲精练,帮助程序员吊打面试官,获得心仪工作机会。</span> </p>
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页