今天写了一个在投票栏目下增加主题的代码
看代码:
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
Code
1 using System;
2 using System.Data;
3 using System.Configuration;
4 using System.Collections;
5 using System.Web;
6 using System.Web.Security;
7 using System.Web.UI;
8 using System.Web.UI.WebControls;
9 using System.Web.UI.WebControls.WebParts;
10 using System.Web.UI.HtmlControls;
11
12 public partial class subjects : System.Web.UI.Page
13 {
14 protected void Page_Load(object sender, EventArgs e)
15 {
16 if (!IsPostBack)//在未增加IsPostBack之前 使用DownList1.SelectValue获取数据,数据库添加的总是为1,DropDownList2能插入所选项的值。
17 {
18 string sql = "select t_name,t_id from Topics";
19 DropDownList1.DataSource = Class1.getDataReader(sql);
20 DropDownList1.DataTextField = "t_name";
21 DropDownList1.DataValueField = "t_id";
22 DropDownList1.DataBind();
23 }
24 }
25 protected void Button1_Click(object sender, EventArgs e)
26 {
27 string sql="insert into subjects(s_name,s_mode,s_tid)values('"+TextBox1.Text+"', '"+DropDownList2.SelectedValue+"','"+DropDownList1.SelectedValue+"')";
28 Class1.ExeCommand(sql);
29 }
30 }
31
32
Code
Code
posted @
2009-03-04 18:32
zxlin25
阅读(
166)
评论()
编辑
收藏
举报