using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient ;
using System.Configuration;
namespace WebNews.admin
{
    /// <summary>
    /// diaocha 的摘要说明。
    /// </summary>
    public class diaocha : System.Web.UI.Page
    {
        protected System.Data.SqlClient.SqlConnection Sqlconn;//添加数据库的操作对象
        protected System.Data.SqlClient.SqlDataAdapter SqlDataAter;
        protected System.Data.DataSet listDateset;
        protected System.Data.SqlClient.SqlCommand SqlCommand1;
        protected System.Data.SqlClient.SqlDataReader SqlDataReader1;
        protected System.Web.UI.WebControls.Label Label1;
        protected System.Web.UI.WebControls.Panel Panel1;
        protected System.Web.UI.WebControls.RadioButtonList RadioButtonList2;
    
        private void Page_Load(object sender, System.EventArgs e)
        {
            
            // 在此处放置用户代码以初始化页面
            if(!Page.IsPostBack)
            {
                
            
            
                    bindRadioButtonList();
            
                
             }    // 在此处放置用户代码以初始化页面
    
        }
        private void bindRadioButtonList()
        {
        
        SqlConnection Sqlconn = new SqlConnection(ConfigurationSettings.AppSettings["dsn"]);
        SqlDataAdapter SqlDataAter = new SqlDataAdapter();
        SqlDataAter.SelectCommand = new SqlCommand("selct * from radio",Sqlconn);
        DataSet listDateset=new DataSet();       
            try
            {
                SqlDataAter.Fill(listDateset);
            }
            catch (SqlException e1)
            {
                Label1.Text ="数据库操作错误:"+e1.Message;                
            }            
            RadioButtonList2.DataSource=listDateset;                                      //绑定RadioButtonList
            RadioButtonList2.DataTextField="name";
            RadioButtonList2.DataValueField="type";
            RadioButtonList2.DataBind();
            foreach(ListItem li in RadioButtonList2.Items)                     //选中分类名
            {
                
            }    
            
        
        }//获取数据库中的值
            #region Web 窗体设计器生成的代码
            override protected void OnInit(EventArgs e)
            {
                //
                // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
                //
                InitializeComponent();
                base.OnInit(e);
            }
        
        /// <summary>
        /// 设计器支持所需的方法 - 不要使用代码编辑器修改
        /// 此方法的内容。
        /// </summary>
        private void InitializeComponent()
        {    
            this.Load += new System.EventHandler(this.Page_Load);
        }
        #endregion
    }      
}  
        
        
代码如上
为什么会棒定不到数据库原
高手指点一下`````````
[此贴子已经被作者于2006-9-23 12:40:31编辑过]



 
											





 
	    

 
	
