zoukankan      html  css  js  c++  java
  • ListView

    <body>
        <form id="form1" runat="server">
        <div>
            <table>
                <thead>
                    <tr>
                        <th>
                            工号
                        </th>
                        <th>
                            姓名
                        </th>
                        <th>
                            性别
                        </th>
                        <th>
                            部门
                        </th>
                        <th>
                            角色
                        </th>
                    </tr>
                </thead>
                <tbody>
                    <asp:ListView ID="LV" runat="server" ItemPlaceholderID="itemPlaceHolder"> 
                        <ItemTemplate>
                            <tr>
                                <td>
                                    <%# Eval("id") %>
                                </td>
                                <td>
                                    <%# Eval("name") %>
                                </td>
                                <td>
                                    <%# Eval("sex") %>
                                </td>
                                <td>
                                    <%# Eval("dep") %>
                                </td>
                                <td>
                                    <%# Eval("character")%>
                                </td>
                            </tr>
                        </ItemTemplate>
                    </asp:ListView>
                </tbody>
            </table>
        </div>
        </form>
    </body>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack) {
                BindData();
            }
        }
    
        private void BindData(){
            string sql = "select * from employee";
            LV.DataSource = new OraSqlHelper().GetEmployees(sql);
            LV.DataBind();
        }
    public List<Employee> GetEmployees(string sql)
        {
            List<Employee> employees = new List<Employee>();
            OracleDataReader result = null;
    
            OracleConnection conn = new OracleConnection(conStr);
            conn.Open();
            OracleCommand cmd = new OracleCommand(sql, conn);
            //从数据库中读取数据流存入result中
            result = cmd.ExecuteReader();
    
            while (result.Read())
            {
                Employee employee = new Employee();
    
                //result.GetOrdinal("id")是得到ID所在列的index, 
                //result.GetInt32(int n)这是将第n列的数据以Int32的格式返回 
                //result.GetString(int n)这是将第n列的数据以string 格式返回
                //result.GetDateTime(int n)这是将第n列的数据以string 格式返回
    
                //判断数据是否为空
                //objId != DBNull.Value判断对象是否为空
                //!Convert.IsDBNull(objScsj)判断DateTime是否为空
                //对象.IsNull("字段")
                //对象.ToString() == ""
                var objId = result.GetValue(result.GetOrdinal("id"));
                if (objId != DBNull.Value)
                {
                    employee.id = Convert.ToInt32(objId);
                }
                var objName = result.GetValue(result.GetOrdinal("name"));
                if (objName != DBNull.Value)
                {
                    employee.name = objName.ToString();
                }
                var objWjjid = result.GetValue(result.GetOrdinal("sex"));
                if (objWjjid != DBNull.Value)
                {
                    employee.sex = objWjjid.ToString();
                }
                var objDep = result.GetValue(result.GetOrdinal("dep"));
                if (objDep != DBNull.Value)
                {
                    employee.dep = objDep.ToString();
                }
                var objCharacter = result.GetValue(result.GetOrdinal("character"));
                if (objCharacter != DBNull.Value)
                {
                    employee.character = objCharacter.ToString();
                }
    
                //格式化输出数据
                //Console.Write("ID:{0},Name:{1},PWD:{2},Age:{3},Sex:{4},Phone{5},Address:{6}
    ", id, name, pwd, age, sex, phone, address);
                employees.Add(employee);
            }
    
            conn.Close();
            conn.Dispose();
            return employees;
        }
  • 相关阅读:
    gvim编辑器 命令列表
    svn 使用
    php 实现 从一个目录中 把指定类型文件 重新组装到新的目录
    gvim 编辑器代码折叠
    简单的 文件 管理操作
    javascript DOM object 操作
    gvim代码补全
    gvim 编辑器配置
    javascript DOM model操作
    SQL分页语句 (转载)
  • 原文地址:https://www.cnblogs.com/huangj/p/7698371.html
Copyright © 2011-2022 走看看