最好能把前台的代码,和程序的代码完整的讲下
在此先谢谢了。
前台代码:
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"
CellPadding="3" DataSourceID="SqlDataSource1" PageSize="30" Width="100%" BackColor="#F1F9FE"
CellSpacing="2" GridLines="None" AutoGenerateColumns="False" DataKeyNames="articleid">
<PagerSettings FirstPageText="首页" LastPageText="尾页" Mode="NumericFirstLast" PageButtonCount="20" />
<PagerStyle HorizontalAlign="Center" />
<HeaderStyle BackColor="#DBEEFB" Wrap="False" />
<AlternatingRowStyle BackColor="#DBEEFB" HorizontalAlign="Center" />
<RowStyle HorizontalAlign="Center" />
<Columns>
<asp:BoundField DataField="articleid" HeaderText="ID" InsertVisible="False" ReadOnly="True"
SortExpression="articleid">
<ItemStyle Wrap="False" />
<HeaderStyle Wrap="False" />
</asp:BoundField>
<asp:BoundField DataField="title" HeaderText="文章标题" SortExpression="title">
<ItemStyle Wrap="False" />
<HeaderStyle Wrap="False" />
</asp:BoundField>
<asp:BoundField DataField="name" HeaderText="作者" SortExpression="name">
<ItemStyle Wrap="False" />
<HeaderStyle Wrap="False" />
</asp:BoundField>
<asp:BoundField DataField="dateandtime" HeaderText="发布日期" SortExpression="dateandtime">
<ItemStyle Wrap="False" />
<HeaderStyle Wrap="False" />
</asp:BoundField>
<asp:BoundField DataField="typeid" HeaderText="分类" SortExpression="typeid">
<ItemStyle Wrap="False" />
<HeaderStyle Wrap="False" />
</asp:BoundField>
<asp:CommandField HeaderText="删除" ShowDeleteButton="True">
<HeaderStyle Wrap="False" />
<ItemStyle Wrap="False" />
</asp:CommandField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:loveconn %>"
DeleteCommand="DELETE FROM [learning] WHERE [articleid] = @articleid" InsertCommand="INSERT INTO [learning] ([user_id], [name], [title], [content], [hits], [dateandtime], [images], [typeid], [review], [reviewcount], [fenshu], [persons]) VALUES (@user_id, @name, @title, @content, @hits, @dateandtime, @images, @typeid, @review, @reviewcount, @fenshu, @persons)"
SelectCommand="SELECT * FROM [learning] ORDER BY [articleid] DESC" UpdateCommand="UPDATE [learning] SET [user_id] = @user_id, [name] = @name, [title] = @title, [content] = @content, [hits] = @hits, [dateandtime] = @dateandtime, [images] = @images, [typeid] = @typeid, [review] = @review, [reviewcount] = @reviewcount, [fenshu] = @fenshu, [persons] = @persons WHERE [articleid] = @articleid">
<DeleteParameters>
<asp:Parameter Name="articleid" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="user_id" Type="Int32" />
<asp:Parameter Name="name" Type="String" />
<asp:Parameter Name="title" Type="String" />
<asp:Parameter Name="content" Type="String" />
<asp:Parameter Name="hits" Type="Int32" />
<asp:Parameter Name="dateandtime" Type="DateTime" />
<asp:Parameter Name="images" Type="String" />
<asp:Parameter Name="typeid" Type="Int32" />
<asp:Parameter Name="review" Type="String" />
<asp:Parameter Name="reviewcount" Type="Int32" />
<asp:Parameter Name="fenshu" Type="Single" />
<asp:Parameter Name="persons" Type="Int32" />
<asp:Parameter Name="articleid" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="user_id" Type="Int32" />
<asp:Parameter Name="name" Type="String" />
<asp:Parameter Name="title" Type="String" />
<asp:Parameter Name="content" Type="String" />
<asp:Parameter Name="hits" Type="Int32" />
<asp:Parameter Name="dateandtime" Type="DateTime" />
<asp:Parameter Name="images" Type="String" />
<asp:Parameter Name="typeid" Type="Int32" />
<asp:Parameter Name="review" Type="String" />
<asp:Parameter Name="reviewcount" Type="Int32" />
<asp:Parameter Name="fenshu" Type="Single" />
<asp:Parameter Name="persons" Type="Int32" />
</InsertParameters>
</asp:SqlDataSource>
后台代码:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class huiyuan_zhiding : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Response.Cache.SetCacheability(HttpCacheability.NoCache);
}
private void GridViewBind()
{
string sqlstr = "";
if (name.Text.Trim() == "")
{
sqlstr = "select * from learning order by articleid desc";
}
else
{
sqlstr = "select * from learning where name like '" + name.Text.Trim() + "' order by articleid desc";
}
string connstr = ConfigurationManager.ConnectionStrings["loveconn"].ConnectionString;
DataSet ds = new DataSet();
SqlConnection conn = new SqlConnection(connstr);
try
{
if (conn.State.ToString() == "Closed")
conn.Open();
SqlDataAdapter da = new SqlDataAdapter(sqlstr, conn);
da.Fill(ds);
GridView1.DataSource = ds.Tables[0].DefaultView;
GridView1.DataBind();
}
catch (Exception ex)
{
Response.Write("数据库错误,错误原因:" + ex.Message);
Response.End();
}
finally
{
if (conn.State.ToString() == "Open")
conn.Close();
}
}
}
现在这个是没有任何错误提示,就是搜索不管用。
搜索解决了,谢谢
还有一点问题,就是默认的页面是空的,只有点击搜索之后,才会出来数据。
怎么打开这个页面的时候,默认的就显示数据。
还有就是搜索数据为空,显示出来的数据,点击翻页的时候,提示: