【Vegas原创】GridView跨页选择多行数据,并循环添加一行DataSet数据

Utility.aspx.cs:(主页面)

 

         try
        {
             DataTable dt 
=   new  DataTable();
            
// 获取Utility_Pre.aspx多个ID Session
             string [] strArrUtilizeID  =  Session[ " utilizeID " ].ToString().Split( ' ; ' );
             
            
// ID循环
             for  ( int  i  =   0 ; i  <  strArrUtilizeID.Length - 1 ; i ++ )
            {
                 
// 获取数据库
                SqlParameter[] sqlParam  =   new  SqlParameter[ 1 ];
                sqlParam[
0 =   new  SqlParameter( " @utilizeID " , SqlDbType.Int,  4 , ParameterDirection.Input,  false 0 0 " @utilizeID " , DataRowVersion.Default,strArrUtilizeID[i].ToString());
                ds 
=  db.GetDataSet( " procUtility " , sqlParam);
                
// DataTable初始化
                # region dt Column
                
if  (i  ==   0 )
                {
                    
for  ( int  intColumn  =   0 ; intColumn  <  ds.Tables[ 0 ].Columns.Count; intColumn ++ )
                    {
                        dt.Columns.Add(ds.Tables[
0 ].Columns[intColumn].ColumnName);
                    }
                }
                # endregion
                
// DataRow 初始化
                DataRow dr  =  dt.NewRow();
                
for  ( int  intCol  =   0 ; intCol  <  ds.Tables[ 0 ].Columns.Count; intCol ++ )
                {
                  
                    
#region   dr
                    
if  (ds.Tables[ 0 ].Columns[intCol].ColumnName  ==   " M_Piece "   ||  ds.Tables[ 0 ].Columns[intCol].ColumnName  ==   " M_Utilize " )
                    {
                        
try
                        {
                            dr[intCol] 
=   decimal .Parse(ds.Tables[ 0 ].Rows[ 0 ][intCol].ToString());
                        }
                       
catch
                        {
                            dr[intCol] 
=   0 ;
                        }
                    }
                    
else   if  (ds.Tables[ 0 ].Columns[intCol].ColumnName  ==   " UpdateDate " )
                    {
                        
try
                        {
                            dr[intCol] 
=  DateTime.Parse(ds.Tables[ 0 ].Rows[ 0 ][intCol].ToString());
                        }
                        
catch
                        {
                            dr[intCol] 
=  DateTime.Now;
                        }
                    }
                    
else
                    {
                        dr[intCol] 
=  ds.Tables[ 0 ].Rows[ 0 ][intCol].ToString();
                    }
                    # endregion   
                   
                }

                dt.Rows.Add(dr);    
               
            }

            grdUtility.DataSource 
=  dt;
            grdUtility.DataBind();
        }
        
catch  (Exception e)
        {
            
string  strEX  =  e.ToString();
        }

 

 

Utility_Pre.aspx.cs

 

     protected   void  btnOK_Click( object  sender, EventArgs e)
    {
        
string  strUID  =   "" ;
        
for  ( int  i  =   0 ; i  <  grdPre.Rows.Count; i ++ )
        {
            
if  (((CheckBox)grdPre.Rows[i].Cells[ 0 ].FindControl( " item " )).Checked  ==   true )
            {
                
string  strD  =  ((Label)grdPre.Rows[ 0 ].Cells[ 10 ].FindControl( " Label1 " )).Text;
                
string  strM  =  ((Label)grdPre.Rows[ 0 ].Cells[ 11 ].FindControl( " Label2 " )).Text;
                
string  strSql  =   " select max(utilizeID) from t_bputilize " ;
                DataSet ds 
=  db.GetDataSet(strSql);
                
int  intU  =   int .Parse(ds.Tables[ 0 ].Rows[ 0 ][ 0 ].ToString()) + 1 ;

                strSql 
=   " insert into t_bputilize(utilizeID,MoelGroupID,DetailID) values(' " + intU + " ',' "   +  strM  +   " ',' "   +  strD  +   " ') " ;
                db.ExecuteNonQuery(strSql);

              strUID 
=  strUID + intU.ToString() + " ; " ;
                
            }
        }
        Session[
" utilizeID " =  strUID;
        Response.Write(
" <script>window.opener.refresh();window.close()</script> " );
    }

 

Utility_Pre.aspx:

 

     < yyc:SmartGridView  ID ="grdPre"  runat ='server'  AutoGenerateColumns ="False" >
         
< HeaderStyle  CssClass ="grid_head"   />
        
< Columns >
             
< asp:TemplateField >
                
< headertemplate >
                    
< asp:CheckBox  ID ="all"    runat ="server"   />
                
</ headertemplate >
                
< itemtemplate >
                    
< asp:CheckBox   ID ="item"   runat ="server"   />
                
</ itemtemplate >
                 
< itemstyle  width ="50px"   />
            
</ asp:TemplateField >
            
< asp:BoundField  DataField ="CMALPH"  HeaderText ="Customer"   />
            
< asp:BoundField  DataField ="Size"  HeaderText ="Size"   />
            
< asp:BoundField  DataField ="TACFilm"  HeaderText ="TACFilm"   />
            
< asp:BoundField  DataField ="Treatment"  HeaderText ="Treatment"   />
            
< asp:BoundField  DataField ="thickness"  HeaderText ="Thickness"   />
            
< asp:BoundField  DataField ="Tablets"  HeaderText ="T/B"   />
            
< asp:BoundField  DataField ="AbsorAngle"  HeaderText ="Absorption Angle"   />
            
< asp:BoundField  DataField ="DimensionX"  HeaderText ="Dimension_X"   />
            
< asp:BoundField  DataField ="DimensionY"  HeaderText ="Dimension_Y"   />
            
< asp:TemplateField  HeaderText ="DetailID"   visible ="false" >
                
< edititemtemplate >
< asp:TextBox  runat ="server"  Text ='<%#  Bind("DetailID") % > '  id="TextBox1"> </ asp:TextBox >
</ edititemtemplate >
                
< itemtemplate >
< asp:Label  runat ="server"  Text ='<%#  Bind("DetailID") % > ' id="Label1"> </ asp:Label >
</ itemtemplate >
            
</ asp:TemplateField >
            
< asp:TemplateField   HeaderText ="ModelGroupID"  visible ="false" >
                
< edititemtemplate >
< asp:TextBox  runat ="server"  Text ='<%#  Bind("ModelGroupID") % > ' id="TextBox2"> </ asp:TextBox >
</ edititemtemplate >
                
< itemtemplate >
< asp:Label  runat ="server"  Text ='<%#  Bind("ModelGroupID") % > ' id="Label2"> </ asp:Label >
</ itemtemplate >
            
</ asp:TemplateField >
            
</ Columns >
              
< CascadeCheckboxes  >
            
< yyc:CascadeCheckbox  ChildCheckboxID ="item"   ParentCheckboxID ="all"   />
        
</ CascadeCheckboxes >
        
</ yyc:SmartGridView >
        
< asp:Button  ID ="btnOK"  runat ="server"   OnClick ="btnOK_Click"  Text ="确定"   /></ div >

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值