温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:商务维基网源码
当前文件:
MerchantViki/Default.aspx.cs,打开代码结构图
MerchantViki/Default.aspx.cs,打开代码结构图1using System; 2
using System.Data; 3
using System.Data.SqlClient; 4
using System.Configuration; 5
using System.Collections; 6
using System.Web; 7
using System.Web.Security; 8
using System.Web.UI; 9
using System.Web.UI.WebControls; 10
using System.Web.UI.WebControls.WebParts; 11
using System.Web.UI.HtmlControls; 12
//该源码下载自www.51aspx.com(51aspx.com) 13
14
public partial class _Default : System.Web.UI.Page 15
{ 16
protected void Page_Load(object sender, EventArgs e) 17
{ 18
this.Header.Title = Application.Get("siteName") + "---" + this.Header.Title; 19
20
if (!Page.IsPostBack) 21
{ 22
BindData(); 23
if (Session["userName"] != null) 24
{ 25
userInfoLbl.Text = "欢迎您:" + Session["userName"].ToString(); 26
if (Session["userPoint"] != null) 27
userInfoLbl.Text += "<br />积分:" + Session["userPoint"].ToString(); 28
} 29
else 30
{ 31
userInfoLbl.Text = "当前用户为游客。"; 32
} 33
34
timeInfoLbl.Text = "今天是" + DateTime.Today.Year.ToString() + "年" + DateTime.Today.Month.ToString() + "月" + DateTime.Today.Day.ToString() + "日"; 35
//timeInfoLbl.Text = "今天是" + DateTime.Now.ToShortDateString(); 36
} 37
} 38
39
private void BindData() 40
{ 41
try 42
{ 43
string conStr = Application.Get("conStr").ToString(); 44
SqlConnection sqlCon = new SqlConnection(conStr); 45
46
string cmdStr = null; 47
SqlCommand sqlCmd = new SqlCommand(); 48
SqlDataReader sqlDR; 49
50
sqlCon.Open(); 51
cmdStr = "select name,id from edition where isOpen = '是'"; 52
sqlCmd.CommandText = cmdStr; 53
sqlCmd.Connection = sqlCon; 54
sqlDR = sqlCmd.ExecuteReader(); 55
56
openEdList.DataSource = sqlDR; 57
openEdList.DataTextField = "name"; 58
openEdList.DataValueField = "id"; 59
openEdList.DataBind(); 60
61
sqlDR.Close(); 62
63
cmdStr = "select name,id from edition where isOpen = '否'"; 64
sqlCmd.CommandText = cmdStr; 65
sqlCmd.Connection = sqlCon; 66
sqlDR = sqlCmd.ExecuteReader(); 67
68
privateEdList.DataSource = sqlDR; 69
privateEdList.DataTextField = "name"; 70
privateEdList.DataValueField = "id"; 71
privateEdList.DataBind(); 72
73
sqlDR.Close(); 74
75
cmdStr = "select top 10 id,name,articleNum,click,createTime from edition where isopen='是' order by click desc "; 76
SqlDataAdapter sqlDA = new SqlDataAdapter(cmdStr, sqlCon); 77
DataSet ds = new DataSet(); 78
79
sqlDA.Fill(ds, "edition"); 80
81
DataGrid1.DataSource = ds.Tables["edition"].DefaultView; 82
83
DataGrid1.DataBind(); 84
85
//sqlDR.Close(); 86
sqlCon.Close(); 87
infoLbl.Text += "数据绑定成功。"; 88
} 89
catch (Exception ex) 90
{ 91
//Response.Write("<script>alert('操纵错误:" + ex.Message + "');</script>"); 92
//throw new Exception(ex.Message, ex); 93
infoLbl.Text += ex.Message; 94
} 95
} 96
97
public void openEdBtn_Click(object sender, EventArgs e) 98
{ 99
infoLbl.Text = openEdList.SelectedValue; 100
Response.Redirect("articleList.aspx?EditionID="+ openEdList.SelectedValue +"", false); 101
} 102
103
public void privateEdBtn_Click(object sender, EventArgs e) 104
{ 105
infoLbl.Text = privateEdList.SelectedValue; 106
Response.Redirect("articleList.aspx?EditionID=" + privateEdList.SelectedValue + "", true); 107
} 108
} 109





}
}