asp.net (C#)DropDownList从不同数据库进行数据绑定

开发使用了master 以及工厂架构  代码没有我没有再重写  后台代码只留了个  绑定代码  主要是看个思路

前台页面

<%@ Page Language="C#" MasterPageFile="~/Consortium/MasterPage.master" AutoEventWireup="true" CodeFile="ConDuty_Add.aspx.cs" Inherits="Consortium_ConDuty_Add" Title="Untitled Page" %>
<%@ Register Src="ConMenu.ascx" TagName="ConMenu" TagPrefix="men" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<men:ConMenu ID="ConMenu1" runat="server" /> 
<div id="SpacesMiddle" style="left: 330px; top: 101px">
    <div id="Whatever">
    <ul class="TabBarLevel1" id="TabPage1">
                <li id="Tab1"><a href="Manage_Consortium.aspx">基本信息</a></li><li id="Tab2" >
                    <a href="News_Add.aspx" >发布新闻</a></li><li id="Tab3" >
                    <a href="Manage_ConDuty.aspx">管理职务</a></li><li id="Tab4" class="Selected">
                    <a href="ConDuty_Add.aspx">添加职务</a></li></ul>
                    <div class="HackBox" style="display: block">
                         <fieldset>
                        <legend>类别管理</legend>
                        <p>
                            <label for="author">
                               职务名称: <span class="required">(必填)</span></label>
                            <asp:TextBox ID="txtSortName" runat="server"></asp:TextBox>
                            <asp:DropDownList ID="dstConUser" runat="server">
                            </asp:DropDownList></p>
                        <p>

                               <asp:Button ID="btnSave" runat="server" Text="保存信息" CssClass="ButtonCss" OnClick="btnSave_Click" />
                        </p>
                         </fieldset>              
                     </div>
                    </div>
                    </div>
</asp:Content>

 

后台代码页


 using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Consortium_ConDuty_Add : System.Web.UI.Page
{
    public string ConId = String.Empty;
    protected void Page_Load(object sender, EventArgs e)
    {
        ConUserData();
    }

    protected void ConUserData()
    {
        SchoolShop.Common.Common com = new SchoolShop.Common.Common();
        DataSet ds = new DataSet();
        DataSet ds1 = null;
        ds = com.GetList(SchoolShop.DBUtility.MsSql.ConnectionStringSpaces, "ConUser", "ConId='" + ConId + "'");
        ds.Tables[0].Columns.Add(new DataColumn("TrueName",typeof(string)));
        for( int i=0;i<ds.Tables[0].Rows.Count;i++)
        {
        ds1 = com.GetList(SchoolShop.DBUtility.MsSql.ConnectionStringSchoolShop, "UserInfo", "UserId='" + ds.Tables[0].Rows[i]["UserId"].ToString() + "'");
        ds.Tables[0].Rows[i]["TrueName"] = ds1.Tables[0].Rows[0]["TrueName"];
        }
        dstConUser.DataSource = ds.Tables[0].DefaultView;
        dstConUser.DataTextField = "TrueName";
        dstConUser.DataValueField = "UserId";
        dstConUser.DataBind();
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值