添加材料,需要绑定材料类型、设备名称、省份和所属终端客户等信息,前台页面如下:

前台.aspx

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

<p>
        BarCode:<asp:TextBox ID="txt_barcode" runat="server"></asp:TextBox>
    </p>
    <p>
        MaterialType:<asp:DropDownList ID="ddlmaterialtype" runat="server" Height="16px"
            Width="125px" AutoPostBack="True">
        </asp:DropDownList>
    </p>
    <p>
        TerminalName:<asp:DropDownList ID="ddlTerminal" runat="server" Height="16px"
            Width="126px" AutoPostBack="True" >
        </asp:DropDownList>
    </p>
    <p>
        Provinces:<asp:DropDownList ID="ddlProvince" runat="server" Height="16px"
            Width="111px">
        </asp:DropDownList>
  
    </p>
    <p>
   DeviceName:<asp:DropDownList ID="ddlDevice" runat="server"
            Height="16px" Width="125px">
        </asp:DropDownList>
    </p>
    <p>
        UseTime:
        <asp:TextBox ID="tb_usetime" runat="server"></asp:TextBox>
    </p>
    <p>
        Status:<asp:RadioButtonList ID="rbStatus" runat="server" AutoPostBack="True"
            RepeatDirection="Horizontal">
            <asp:ListItem Selected="True" Value="0">sended</asp:ListItem>
            <asp:ListItem Value="1">inBox</asp:ListItem>
            <asp:ListItem Value="2">Used</asp:ListItem>
        </asp:RadioButtonList>
    </p>
    <p>
        <asp:Button ID="btnOk" runat="server" onclick="btnOk_Click" Text="comfirm" />
&nbsp;&nbsp;
        <asp:Button ID="btncancel" runat="server" onclick="btncancel_Click"
            Text="cancel" />
    </p>

</asp:Content>

后台aspx.cs:

private SqlConnection conn;
        private SqlCommand cmd;
        private const string connStr = "Data Source=SZXY1ZWX2166591\\SQLEXPRESS;Initial Catalog=DbDevice;Integrated Security=True";

protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.tb_usetime.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");

BindMaterialType();
                BindTerminal();
            }
        }

void BindTerminal()
         {
             string terminalsql = "select m.TerminalID,m.TerminalName from Tbl_Terminal m";
             DataTable dt = GetTable(terminalsql);
             if (dt != null && dt.Rows.Count > 0)
             {
                 this.ddlTerminal.DataSource = dt;
                 this.ddlTerminal.DataTextField = "TerminalName";
                 this.ddlTerminal.DataValueField = "TerminalID";
                 this.ddlTerminal.DataBind();
             }
         }
        void BindMaterialType()
        {
            string sql = "select t.TypeId,t.TypeName from Tbl_ComsumerMaterialType t";
            DataTable dt=  GetTable(sql);
            if (dt != null && dt.Rows.Count > 0)
            {
                this.ddlmaterialtype.DataSource = dt;
                this.ddlmaterialtype.DataTextField = "TypeName";
                this.ddlmaterialtype.DataValueField = "TypeId";
                this.ddlmaterialtype.DataBind();
            }
        }

#region 数据库操作
   /// <summary>  
        /// 打链接   
        /// </summary>    
        ///<returns></returns> 
        private SqlConnection GetConn()
        {         
            if (conn == null)
                conn = new SqlConnection(connStr); 
            if (conn.State == ConnectionState.Closed)
                conn.Open();        
            else if (conn.State == ConnectionState.Broken)     
            {          
                conn.Close();       
                conn.Open();       
            }            return conn; 
        } 
                 /// <summary>   
                  /// 执行增删改查操作
                  /// </summary>  
                  /// <param name="sql"></param> 
                 /// <returns></returns> 
                 private int ExecuteNonQuery(string sql)   
                 {         
                     try       
                     {            
                         cmd = new SqlCommand(sql, GetConn());     
                         return cmd.ExecuteNonQuery();      
                     }       
                     catch     
                     {       
                         return 0; 
                     }        
                     finally    
                     {        
                         conn.Close();  
                     }   
                 }      
        /// <summary>   
        /// 读数据
         /// </summary>  
         /// <param name="sql"></param> 
         /// <returns></returns>  
        private SqlDataReader ExecuteReader(string sql)  
       {       
            try  
            {          
                cmd = new SqlCommand(sql, GetConn());   
                return cmd.ExecuteReader();      
            }        
            catch        
            {           
                return null; 
            }         
            finally     
            {       
                conn.Close();   
            }   
        }      
       
        /// <summary>    
         /// 该表数据 
        /// </summary> 
        /// <param name="sql"></param>   
         /// <returns></returns>
         private DataTable GetTable(string sql) 
         {         
         try         
         {          
         SqlDataAdapter da = new SqlDataAdapter(sql, GetConn());
             DataSet ds = new DataSet();      
             da.Fill(ds);             
             return ds.Tables[0];    
         }         
         catch        
         {           
             return null;   
         }         
         finally      
         {        
             conn.Close();  
         }     
         }    
        #endregion

protected void btncancel_Click(object sender, EventArgs e)
         {

}

protected void btnOk_Click(object sender, EventArgs e)
         {
             string serialNumber = getdate() + getRandom().ToString();

string status = this.rbStatus.SelectedValue;
             string terminal = this.ddlTerminal.SelectedItem.Value;
             string materialType = this.ddlmaterialtype.SelectedValue;
         }

private int getRandom()
         {
             Random rad = new Random();//实例化随机数产器rad;

int value = rad.Next(1000, 10000);//

return value;
         }
         private string getdate()
         {
             string date = DateTime.Now.ToString("yyyyMMddHHmmss");
             return date;
         }

绑定多个ddl的更多相关文章

  1. FineUI(开源版)v6.0中FState服务器端验证的实现原理

    前言 1. FineUI(开源版)是完整开源,最早发起于 2008-04,下载全部源代码:http://fineui.codeplex.com/ 2. 你可以通过捐赠作者来支持FineUI(开源版)的 ...

  2. asp.net c# 网上搜集面试题目大全(附答案)

    1.String str=new String("a")和String str = "a"有什么区别? String str = "a"; ...

  3. [转]asp.net c# 网上搜集面试题目(附答案)

    本文转自:http://www.cnblogs.com/hndy/articles/2234188.html 1.String str=new String("a")和String ...

  4. Asp.net 之页面处理积累(一)

    1.实现超链接跳转网页直接定位到跳转后页面中部,而不是要往下拖,才能看到想看的内容 (1)在跳转后页面想定位的位置加:<a name="middle" id="mi ...

  5. 绑定DDL控件方法

    刚刚写的,用在项目中,先记下来,备忘: 下面是调用方式:

  6. Asp.Net 将枚举类型(enum)绑定到ListControl(DropDownList)控件

    在开发过程中一些状态的表示使用到枚举类型,那么如何将枚举类型直接绑定到ListControl(DropDownList)是本次的主题,废话不多说了,直接代码: 首先看工具类代码: /// <su ...

  7. Repeater的Item项绑定DropDownList

    前台页面: <asp:Repeater ID="rptJgtList" runat="server" OnItemDataBound="rptJ ...

  8. 绑定枚举到dropdownlist

    pageTools.BindEnumToDropdownList(typeof(enumDealerArea), ddlBmwArea, new ListItem("--请选择--" ...

  9. js绑定下拉框

    ---恢复内容开始--- 方法一 js-ajax部分 function GetDListOfCt() { $.ajax({ url: "../../Ajax/Boss_Show.ashx?t ...

随机推荐

  1. 高通平台FastMMI(FFBM模式)简介与进入方法

    参考: http://blog.csdn.net/tfslovexizi/article/details/51499979 http://www.voidcn.com/blog/jimbo_lee/a ...

  2. Obtaining Query Count Without executing a Query in Oracle D2k

    Obtaining Query Count Without executing a Query in Oracle D2k Obtaining a count of records that will ...

  3. 办公大楼3D指纹门禁系统解决方案

    随着人们对工作.生活的自动化水平也提出了越来越高的要求.以大楼安保对出入大楼的外来人员进行登记放行或以铁锁.钥匙和卡为代表的出入管理方式已无法满足需求. 利用科技的手段,实现办公大楼的安全现代化.管理 ...

  4. 简单播放器(增加sdl事件控制)

    #include <libavcodec/avcodec.h> #include <libavformat/avformat.h> #include <libswscal ...

  5. 如何在WPF的DiagramControl中绘制一个类型数据关系图的方法

    https://www.devexpress.com/Support/Center/Question/Details/T418156 虽然是在wpf中,但是在win中也可以调用wpf控件,这个太棒了, ...

  6. C#位运算讲解与示例

    首先每一个权限数都是2的N次方数 如:k1=2 ; //添加 k2=4 ; //删除 k3=8; //修改 ... 如此定义功能权限数,当需要组合权限时,就需要对各个所拥有的权限数按位或了. 如: p ...

  7. (原创)Xilinx的ISE生成模块ngc网表文件

    ISE中,右击“Synthesize”,选中“Process Properties”,将“Xilinx Specific Options:-iobuf”的对勾取消. 将取消模块的ioBuff,因为模块 ...

  8. VB.net的特殊语法(区别于C#.NET)

    1:引入命名空间(Imports) Imports System.Exception Imports System.Data.SqlClient Imports System.Security.Cry ...

  9. Web后台开发技术 经验路线图

    一篇文章:http://www.cnblogs.com/Hiker/archive/2012/11/04/houtaijishu.html

  10. Android之Dialer之紧急号码

    Android之Dialer之紧急号码 e over any other (e.g. supplementary service related) number analysis. a) 112 an ...