自己试着做留言本,遇到很多问题,想在同一页面可以写也可以显示,用了gridview,点击“提交”按钮时没办法写到数据库里。请大家帮忙给看看
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim sql As String
sql = "insert into liuyanben ([name],[neirong]) values('sql = sql & Trim(TextBox2.Text) & Trim(TextBox1.Text) ')"
End Sub //这个函数我不知道该放到哪里<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head >
<title>留言本</title>
</head>
<body runat="server" >
<form id="form1" runat="server">
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"
CellPadding="4" DataSourceID="SqlDataSource1" ForeColor="#333333" GridLines="None"
Height="156px" Width="156px">
<FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#E3EAEB" />
<EditRowStyle BackColor="#7C6F57" />
<SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView> //GridView用的是一个叫liuyanben的数据库 <br />
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:liuyanbenConnectionString %>" //我的数据库连接名命名不太规范 SelectCommand="SELECT * FROM [liuyanben]"></asp:SqlDataSource> <asp:Label ID="Label1" runat="server" Text="姓名"></asp:Label>
<asp:TextBox ID="TextBox2" runat="server" Height="14px" Width="130px"></asp:TextBox><br />
//姓名填写区
<br /> <asp:TextBox ID="TextBox1" runat="server" Height="106px" Width="247px"></asp:TextBox><br />
//留言填写区
<asp:Button ID="Button1" runat="server" Text="提交留言" onclick="Button1_Click"/>
//onclick这个动作不知道定义的对不对
</form>
</body>
</html>
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim sql As String
sql = "insert into liuyanben ([name],[neirong]) values('sql = sql & Trim(TextBox2.Text) & Trim(TextBox1.Text) ')"
End Sub //这个函数我不知道该放到哪里<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head >
<title>留言本</title>
</head>
<body runat="server" >
<form id="form1" runat="server">
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"
CellPadding="4" DataSourceID="SqlDataSource1" ForeColor="#333333" GridLines="None"
Height="156px" Width="156px">
<FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#E3EAEB" />
<EditRowStyle BackColor="#7C6F57" />
<SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView> //GridView用的是一个叫liuyanben的数据库 <br />
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:liuyanbenConnectionString %>" //我的数据库连接名命名不太规范 SelectCommand="SELECT * FROM [liuyanben]"></asp:SqlDataSource> <asp:Label ID="Label1" runat="server" Text="姓名"></asp:Label>
<asp:TextBox ID="TextBox2" runat="server" Height="14px" Width="130px"></asp:TextBox><br />
//姓名填写区
<br /> <asp:TextBox ID="TextBox1" runat="server" Height="106px" Width="247px"></asp:TextBox><br />
//留言填写区
<asp:Button ID="Button1" runat="server" Text="提交留言" onclick="Button1_Click"/>
//onclick这个动作不知道定义的对不对
</form>
</body>
</html>
解决方案 »
- jqGrid4定义按钮查询(用过jqGrid的高手请进,在线等)
- 关于checkbox无选择时出错求教
- 数据源绑定发生在哪个页面事件中?
- PetShop 4
- 散 200 分 —— Vs.Net 2005 实现 ExoBUD 网站媒体播放器的互动
- 为什么点击下载联接后其它连接就打不开了?
- 如何把一个方法传递的参数对象标记为只读,我忘了。
- 在Sql Server 2005(和visual Web Developer 2005 Express Edition一起安装)怎么还原数据库?
- 服务器控件一定要在runat="server"的form中?
- 谁能告诉我通过上传文件的控件上传去掉文件有大小限制
- 导出GridView模板列中的图片
- 无刷新获得子页面传来的参数
Dim sql As String
sql = "insert into liuyanben ([name],[neirong]) values('sql = sql & Trim(TextBox2.Text) & Trim(TextBox1.Text) ')"
End Sub //这个函数我不知道在这个页面能不能产生效果