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();

                                    }
                                }

                                
                            }
                        }
    }

    冯瑞涛
  • 相关阅读:
    c#基础之Type
    .Net IOC框架入门之三 Autofac
    EF的三种数据加载方式
    EntityFramework扩展之第三方类库
    EF Codefirst入门之创建数据库
    EasyUI combotree的使用
    MacOS 安装 gdb 踩过的坑
    enex 转 md 格式的几种方式(免费版/氪金版)
    C++ 标准库之 iomanip 、操作符 ios::fixed 以及 setprecision 使用的惨痛教训经验总结
    python list 中 remove 的骚操作/易错点
  • 原文地址:https://www.cnblogs.com/finehappy/p/1378653.html
Copyright © 2011-2022 走看看