<tr>
<td style="width:100px; height:26px;"></td>
<td style="width:450px; height:26px;"> <strong>添加新闻</strong></td>
</tr>
<tr>
<td>流水号</td>
<td>
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td style="width:100px; height:26px">新闻标题</td>
<td style="width:450px; height:26px;">
<asp:TextBox ID="TextBox1" runat="server" Width="209px"></asp:TextBox>
</td>
</tr>
<tr>
<td style="width:450px;height:31px;">类别</td>
<td style="width:450px;height:31px;">
<asp:DropDownList ID="DropDownList1" runat="server" Width="120px"></asp:DropDownList>
</td>
</tr>
<tr>
<td style="width:100px;height:182px;">内容</td>
<td style="width:450px;height:182px">
<asp:TextBox ID="TextBox2" runat="server" Height="150px" TextMode="MultiLine" Width="300px"></asp:TextBox>
</td>
</tr>
<tr>
<td style="width:100px;height:20px"></td>
<td style="width:450px;height:20px">
<asp:Button ID="Button1" runat="server" Text="发布" OnClick="Button1_Click" />
</td>
</tr>
</table>
public partial class addnews : System.Web.UI.Page
{ BaseClass ba = new BaseClass();//创建对象
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{//从新闻读取信息并绑定到DropDownList控件中选出其中的一项“新闻类别”
DataTable dt = new DataTable();
string strsql = "select * from 新闻类别表";
dt = ba.readtable(strsql);
DropDownList1.DataSource = dt;
DropDownList1.DataTextField = "新闻类别";
DropDownList1.DataValueField = "新闻类别";
DropDownList1.DataBind();
}
}
protected void Button1_Click(object sender, EventArgs e)
{//执行的增加操作并清空各个text
string strsql="insert into 新闻信息表(流水号,新闻标题,新闻内容,新闻类别,添加时间,阅读次数)
values ('"+TextBox3.Text+"','"+TextBox1.Text+ "','" + TextBox2.Text + "',
'"+DropDownList1.SelectedValue+"','"+System.DateTime.Now.ToString()+"','"+0+"')";
ba.execsql(strsql);
Response.Write("发布成功");
TextBox1.Text = "";
TextBox2.Text = "";
TextBox3.Text = "";
}
}