现在的位置: 首页 > 综合 > 正文

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

2013年10月11日 ⁄ 综合 ⁄ 共 11461字 ⁄ 字号 评论关闭

 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"
                                onblur="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" 
                                onblur="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" onblur="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" onblur="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" onblur="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" onblur="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" onblur="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);
               }

 

抱歉!评论已关闭.