我編寫了此代碼以從HTML字段中獲取消息信息,然後執行插入命令。但是InsertCommand沒有執行。這裏有什麼問題?FormParameter無法正常工作
<form action="FormParameter.aspx" method="post">
<label >Title :</label>
<input id="txtTitle" type="text" /><br />
<label >Subject:</label>
<input id="txtSubject" type="text" /><br />
<label >Category: </label>
<input id="txtCategory" type="text" /><br />
<input id="btnAdd" type="submit" value="Add" />
</form>
<form id="form1" runat="server">
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:MessagesConnectionString %>"
InsertCommand="INSERT INTO [Messages] ([Title], [Subject], [CategoryID]) VALUES (@Title, @Subject, @CategoryID)"
SelectCommand="SELECT * FROM [Messages]" >
<InsertParameters>
<asp:FormParameter Name="Title" FormField="txtTitle" DefaultValue="No Title" />
<asp:FormParameter Name="Subject" FormField="txtSubject" DefaultValue="No Subject" />
<asp:FormParameter Name="CategoryID" FormField="txtCategory" DefaultValue="No Category" />
</InsertParameters>
</asp:SqlDataSource>
</form>
</body>
</html>
,並在的CodeFile(FormParameter.aspx.cs)
void Page_Load()
{
if (Request.Form["btnAdd"] != null)
SqlDataSource1.Insert();
}
爲什麼不使用ASP.NET服務器控件? – 2012-03-10 17:53:33
我正在學習新東西! – dotfreelancer 2012-03-10 17:55:00
爲什麼-1!你怎麼了 ? – dotfreelancer 2012-03-10 19:36:06