DropDownList控件绑定栏目分类的问题
小弟目前正在做一个文章发布系统,一极栏目,栏目建表:wyx_class,字段有:wyx_id,wyx_classname,wyx_classsort
文章内容建表:wyx_text,字段有:wyx_id,wyx_title,wyx_author,wyx_classtype,wyx_content,wyx_date
现在后台搞添加文章信息的页面出了问题,因为栏目分类用的是DropDownList控件绑定到wyx_class表,就这玩意儿现在不好使
比如我添加一篇文章,栏目选“散文”,“散文”栏目在wyx_class表里的wyx_id是2
文章添加进去后,wyx_text表里的wyx_classtype也应该是2才对,但它不是,是1
当我添加其它文章,选择另外一些栏目分类时,wyx_classtype全都是1
现在的问题也就是添加一篇文章选择好相应的栏目,插入数据库后,文章是进去了,但栏目没有对应
请各位大哥们帮帮忙看看哪里出了问题,谢谢!!!
【前台代码】:
<table border="1" align="center" cellpadding="0" cellspacing="0" class="tableall" bordercolor="#666666">
<tr>
<td colspan="2" class="tabletd1" style="background-color: #666666; text-align: center">
<span style="font-size: 14pt; color: #ffffff"><strong>添加文章信息</strong></span></td>
</tr>
<tr class="tabletd2">
<td width="20%" style="height: 21px"> 栏目分类:</td>
<td style="width: 507px; height: 21px;">
<asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList></td>
</tr>
<tr class="tabletd3">
<td style="height: 24px;"> 文章标题:</td>
<td style="width: 507px; height: 24px;">
<asp:TextBox ID="TextBox1" runat="server" Width="400px"></asp:TextBox></td>
</tr>
<tr class="tabletd3">
<td> 文章作者:</td>
<td style="width: 507px;">
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</td>
</tr>
<tr class="tabletd3">
<td style="height: 19px"> 文章内容:</td>
<td style="width: 507px; height: 19px;">
<asp:TextBox ID="TextBox3" runat="server" Height="300px" TextMode="MultiLine" Width="500px" Font-Names="宋体"></asp:TextBox></td>
</tr>
<tr class="tabletd2">
<td colspan="2" style="text-align: center">
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="提交" /> <input id="Reset1" type="reset" value="清除" /></td>
</tr>
</table>
【后台代码】:
public partial class admin_admin_add : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
string username = (string)Session["username"];
}
DataSet ds = Socut.Data.ExecuteDataSet("select wyx_id,wyx_classname from wyx_class");//实例化DataSet
DropDownList1.DataSource = ds;
DropDownList1.DataTextField = "wyx_classname";
DropDownList1.DataValueField = "wyx_id";
DropDownList1.DataBind(); //绑定数据
}
protected void Button1_Click(object sender, EventArgs e)
{
string strDate = System.DateTime.Now.ToString();//当前时间
Socut.Data.ExecuteNonQuery("INSERT INTO wyx_text (wyx_title,wyx_author,wyx_content,wyx_date,wyx_class) VALUES ('" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox3.Text + "','" + strDate + "','" + DropDownList1.SelectedItem.Value + "')");
Response.Redirect("admin_text.aspx");
}
}