zoukankan      html  css  js  c++  java
  • 一次从GridView 获得多个指定行中多个指定控件的值

    一次从GridView 获得多个指定行中多个指定控件的值,非常初级普通的代码,也没有什么技术难度。

    .aspx

     <asp:GridView ID="GridAssisMater" runat="server" CssClass="gvtab" GridLines="None"
                                        AutoGenerateColumns
    ="False">
                                        
    <PagerSettings Mode="NumericFirstLast" />
                                        
    <Columns>
                                            
    <asp:TemplateField HeaderText="序号">
                                                
    <ItemTemplate>
                                                    
    <%#Container.DataItemIndex+1 %>
                                                
    </ItemTemplate>
                                            
    </asp:TemplateField>
                                            
    <asp:BoundField DataField="M_MaterCoding" HeaderText="材料编码" />
                                            
    <asp:BoundField DataField="M_Name" HeaderText="材料名称" />
                                            
    <asp:BoundField DataField="M_Spec" HeaderText="规格型号" />
                                            
    <asp:BoundField DataField="A_Quantity" HeaderText="订购数量" />
                                            
    <asp:BoundField DataField="A_Price" HeaderText="单价" />
                                            
    <asp:TemplateField HeaderText="入库数量">
                                                
    <ItemTemplate>
                                                    
    <asp:TextBox ID="txt_Change" runat="server" CssClass="inputlineLong"></asp:TextBox>
                                                
    </ItemTemplate>
                                            
    </asp:TemplateField>
                                            
    <asp:TemplateField HeaderText="&lt;input type='checkbox' id='chk' name='chk' onclick='checkJs(this.checked);'  /&gt;全选"
                                                FooterText
    ="全选">
                                                
    <ItemTemplate>
                                                    
    <asp:CheckBox ID="checkboxname" ToolTip='<%# Eval( "CIDX")%>' runat="server" />
                                                
    </ItemTemplate>
                                            
    </asp:TemplateField>
                                        
    </Columns>
                                        
    <AlternatingRowStyle CssClass="tr2" />
                                    
    </asp:GridView>

    .aspx.cs

    以一个提交事件中,你可能需要的是获得当前页面下所有选中指定行的指定控件的值

     protected void Sub_Click(object sender, EventArgs e)

    {
    for (int i = 0; i < this.GridAssisMater.Rows.Count; i++)
                        {
                            ck 
    = (CheckBox)this.GridAssisMater.Rows[i].FindControl("checkboxname");
                            
    if (ck.Checked == true)
                            {
                                TextBox tbtemp 
    = (TextBox)this.GridAssisMater.Rows[i].FindControl("txt_Change");

                                
    using (SqlConnection cn = new SqlConnection(GetLastID.CnString)) //GetLastID.CnString 是自己写的用来获得Config中连接字符串的
                                {
                                    cn.Open();
                                    
    using (SqlCommand cm = cn.CreateCommand())
                                    {
                                        
                                        cm.CommandType 
    = CommandType.Text;
                                        
    //Response.Write("ckb[" + i + "]的值为:" + ckb[i] + "<br>");

                                        
    string strSQL = " insert into dbo.SDS_AssistantInDetail(A_AIDID,A_AssistantInID,A_AuxiliaryDetailID,A_InQuantity) " +
                                                            
    " values('" + Guid.NewGuid() + "','" + PKId.ToString() + "','" + ck.ToolTip + "','" + tbtemp.Text + "') ";
                                        cm.CommandText 
    = strSQL;
                                        cm.ExecuteNonQuery();

                                    }
                                }

                                
                            }
                        }
    }

    冯瑞涛
  • 相关阅读:
    网络七层
    微信小程序开发工具 常用快捷键
    BZOJ 1026 windy数 (数位DP)
    BZOJ 1026 windy数 (数位DP)
    CodeForces 55D Beautiful numbers (SPOJ JZPEXT 数位DP)
    CodeForces 55D Beautiful numbers (SPOJ JZPEXT 数位DP)
    HDU 3709 Balanced Number (数位DP)
    HDU 3709 Balanced Number (数位DP)
    UVA 11361 Investigating Div-Sum Property (数位DP)
    UVA 11361 Investigating Div-Sum Property (数位DP)
  • 原文地址:https://www.cnblogs.com/finehappy/p/1378653.html
Copyright © 2011-2022 走看看