问题描述
.cs代码是这样的代码没错但总是说未将对象引用到实例usingSystem;usingSystem.Data;usingSystem.Configuration;usingSystem.Collections;usingSystem.Web;usingSystem.Web.Security;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;usingSystem.Web.UI.WebControls.WebParts;usingSystem.Web.UI.HtmlControls;usingSystem.Data.SqlClient;publicpartialclass_Default:System.Web.UI.Page{SqlHelperdata=newSqlHelper();protectedvoidPage_Load(objectsender,EventArgse){if(!IsPostBack){using(SqlConnectionconn=newSqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["JHNTCWebCon"].ConnectionString)){conn.Open();SqlDataAdaptersqladp=newSqlDataAdapter("SELECTtop4*FROMSpecialtyorderbyiddesc",conn);DataTabledt=newDataTable();sqladp.Fill(dt);PagedDataSourceSQLpaged=newPagedDataSource();SQLpaged.DataSource=dt.DefaultView;SQLpaged.AllowPaging=true;SQLpaged.PageSize=4;intthis_Page;if(Request.QueryString["Page"]!=null)this_Page=Convert.ToInt32(Request.QueryString["Page"]);elsethis_Page=1;SQLpaged.CurrentPageIndex=this_Page-1;Label1.Text="当前页:"+this_Page.ToString()+"/"+SQLpaged.PageCount;if(!SQLpaged.IsFirstPage)HyperLink1.NavigateUrl=Request.CurrentExecutionFilePath+"?Page="+Convert.ToString(this_Page-1);if(!SQLpaged.IsLastPage)HyperLink2.NavigateUrl=Request.CurrentExecutionFilePath+"?Page="+Convert.ToString(this_Page+1);DataList1.DataSource=SQLpaged;DataList1.DataBind();}}}protectedvoidDataList1_SelectedIndexChanged(objectsender,EventArgse){}}
解决方案
解决方案二:
System.Configuration.ConfigurationManager.ConnectionStrings["JHNTCWebCon"].ConnectionString这段报错了,配置里没JHNTCWebCon这个节点
解决方案三:
怎么说加下我QQ1154625011教下我谢谢大神
解决方案四:
在web.config中增加节点
解决方案五:
具体怎么加节点呢?
解决方案六:
我原本就有的这句<connectionStrings><addname="connStr"connectionString="DataSource=LAAC2Z91MC1RBB0;InitialCatalog=JHNTCWeb;IntegratedSecurity=True"providerName="System.Data.SqlClient"/></connectionStrings>
解决方案七:
你读取的地方配置名叫JHNTCWebCon,你配置里面的配置名叫connStr,两者改为一致的
解决方案八:
网站能跳出来了但它只显示了一页没分页是什么情况
解决方案九:
我的最终目的是datalist结合pageddataSource对象产品展示分页
解决方案十:
我再后台添加了8样东西这只显示了4样还只是一页这怎么解决
解决方案十一:
楼主照着这个例子做,就行了<headrunat="server"><title></title><styletype="text/css">.style3{width:19px;}.style5{width:157px;}.style7{width:133px;}.style8{width:294px;}</style></head><body><formid="form1"runat="server"><div><tableborder="0"cellpadding="0"cellspacing="0"style="width:653px"><tr><tdalign="left"><asp:DataListID="DataList1"runat="server"style="margin-right:5px"Width="600px"onitemcommand="DataList1_ItemCommand"onitemdatabound="DataList1_ItemDataBound"BorderWidth="1px"CellPadding="2"ForeColor="Black"><HeaderStyleFont-Bold="True"/><ItemTemplate><table><trstyle="border-bottom-width:medium;border-bottom-color:#FFFFFF"><tdalign="left"><asp:ImageID="Image7"runat="server"/><a><%#Eval("Image7Name")%></a></td></tr><tr><tdalign="left"class="style7">创建时间:<a><%#Eval("createtime","{0:D}")%></a></td></tr></table></ItemTemplate><AlternatingItemStyleBackColor="PaleGoldenrod"/><FooterStyleBackColor="Tan"/><FooterTemplate><divstyle="text-align:center"><tableid="Page"border="1"cellpadding="0"cellspacing="0"style="font-size:12px;width:68%"><tr><td><asp:LabelID="labCurrentPage"runat="server"></asp:Label>/<asp:LabelID="labPageCount"runat="server"></asp:Label><asp:LinkButtonID="lnkbtnFirst"runat="server"CommandName="first"Font-Underline="False"ForeColor="Black">首页</asp:LinkButton><asp:LinkButtonID="lnkbtnFront"runat="server"CommandName="pre"Font-Underline="False"ForeColor="Black">上一页</asp:LinkButton><asp:LinkButtonID="lnkbtnNext"runat="server"CommandName="next"Font-Underline="False"ForeColor="Black">下一页</asp:LinkButton><asp:LinkButtonID="lnkbtnLast"runat="server"CommandName="last"Font-Underline="False"ForeColor="Black">尾页</asp:LinkButton> 跳转至:<asp:TextBoxID="txtPage"runat="server"Width="35px"Height="21px"></asp:TextBox><asp:ButtonID="Button1"runat="server"CommandName="search"Text="GO"Height="19px"/><br/></td></tr></table></div></FooterTemplate><SelectedItemStyleBackColor="DarkSlateBlue"ForeColor="GhostWhite"/></asp:DataList></td></tr></table></div></form></body></html>
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Web;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;usingSystem.Data;usingSystem.Data.SqlClient;usingSystem.Configuration;publicpartialclass_Default:System.Web.UI.Page{protectedstaticPagedDataSourcepds=newPagedDataSource();protectedvoidPage_Load(objectsender,EventArgse){if(!IsPostBack){BindDataList(0);}}privatevoidBindDataList(intcurrentpage){pds.AllowPaging=true;//允许分页pds.PageSize=10;//每页显示10条数据pds.CurrentPageIndex=currentpage;//这里将数据库连接字符串写在web.config文件中,通过这个语句来调用,这样方便对连接字符串的修改stringconnStr=ConfigurationManager.ConnectionStrings["connStr"].ConnectionString;//创建数据库连接对象SqlConnectioncon=newSqlConnection(connStr)stringstrSql="SELECT*FROMtableC";con.Open();//打开数据库连接SqlDataAdaptersda=newSqlDataAdapter(strSql,con);DataSetds=newDataSet();sda.Fill(ds);//把执行得到的数据放在数据集中pds.DataSource=ds.Tables[0].DefaultView;//把数据集中的数据放入分页数据源中DataList1.DataSource=pds;DataList1.DataBind();con.Close();}protectedvoidDataList1_ItemCommand(objectsource,DataListCommandEventArgse){switch(e.CommandName){case"first"://第一页pds.CurrentPageIndex=0;BindDataList(pds.CurrentPageIndex);break;case"pre"://上一页pds.CurrentPageIndex=pds.CurrentPageIndex-1;BindDataList(pds.CurrentPageIndex);break;case"next"://下一页pds.CurrentPageIndex=pds.CurrentPageIndex+1;BindDataList(pds.CurrentPageIndex);break;case"last"://最后一页pds.CurrentPageIndex=pds.PageCount-1;BindDataList(pds.CurrentPageIndex);break;case"search"://页面跳转页if(e.Item.ItemType==ListItemType.Footer){intPageCount=int.Parse(pds.PageCount.ToString());TextBoxtxtPage=e.Item.FindControl("txtPage")asTextBox;intMyPageNum=0;if(!txtPage.Text.Equals(""))MyPageNum=Convert.ToInt32(txtPage.Text.ToString());if(MyPageNum<=0||MyPageNum>PageCount){Response.Write("<script>alert('请输入页数并确定没有超出总页数!')</script>");txtPage.Text="";}elseBindDataList(MyPageNum-1);}break;}}protectedvoidDataList1_ItemDataBound(objectsender,DataListItemEventArgse){if(e.Item.ItemType==ListItemType.Footer){LabelCurrentPage=e.Item.FindControl("labCurrentPage")asLabel;LabelPageCount=e.Item.FindControl("labPageCount")asLabel;LinkButtonFirstPage=e.Item.FindControl("lnkbtnFirst")asLinkButton;LinkButtonPrePage=e.Item.FindControl("lnkbtnFront")asLinkButton;LinkButtonNextPage=e.Item.FindControl("lnkbtnNext")asLinkButton;LinkButtonLastPage=e.Item.FindControl("lnkbtnLast")asLinkButton;CurrentPage.Text=(pds.CurrentPageIndex+1).ToString();PageCount.Text=pds.PageCount.ToString();if(pds.IsFirstPage){FirstPage.Enabled=false;PrePage.Enabled=false;}if(pds.IsLastPage){NextPage.Enabled=false;LastPage.Enabled=false;}}}}
解决方案十二:
这样的话原先的.cs文件我都不知道怎么改了。。。。改到猴年马月啊
解决方案十三:
引用11楼qq_25046175的回复:
这样的话原先的.cs文件我都不知道怎么改了。。。。改到猴年马月啊
你可以先把你原先的.cs文件复制备份一下。
解决方案十四:
也可以用gridview,分页要简单些
解决方案十五:
看看JHNTCWebCon在config文件里,是否存在