我收到一个错误,不知道我不知道如何解决它 [英] I am getting one error and don't know I don't know how to fix it

查看:89
本文介绍了我收到一个错误,不知道我不知道如何解决它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

错误出现在此代码的最后一个方法的第一个语句中,即CurrentPage = FillRepeater() - 1;对于分页目的,我们将使用PagedDataSource类,它与在其他数据绑定控件中用于分页的类相同。在FillRepeater()中,我创建了PagedDataSource类的对象并利用了它的一些方法。这个简单的属性用于获取当前页面价值如下。这只是使用viewstate来存储Data页面的当前状态。此外,我还将添加链接按钮的功能,其中包含点击事件的第一页,上一页,上一页和下一页。如下所示。



我尝试过:



使用System;

使用System.Collections.Generic;

使用System.Linq;

使用System.Web;

使用System.Web.UI;

使用System.Web.UI.WebControls;

使用System.Data.SqlClient;

使用System.Data;

使用System.Configuration;



public partial class ExamPage:System.Web.UI.Page

{



SqlConnection con;

字符串查询;





公共ExamPage()

{

con = new SqlConnection();

con.ConnectionString = ConfigurationManager.ConnectionStrings [ConnectionString]。ToString();



}





protected void Page_Load(object sender,EventArgs e)

{



}



private int FillRepeater()

{

query =从问题中选择前10个问题,选项1,选项2,选项3,选项4;

SqlCommand cmd = new SqlCommand(query,con);

con 。打开(); SqlDataAdapter da = new SqlDataAdapter(cmd);

DataSet ds = new DataSet();



da.Fill(ds);



PagedDataSource pds = new PagedDataSource();

pds.DataSource = ds.Tables [0] .DefaultView;

pds.AllowPaging = true; pds.PageSize = 8;



int count = pds.PageCount;

pds.CurrentPageIndex = CurrentPage;



if(pds.Count> 0)

{



lbtnPrev.Visible = true;

lbtnNext.Visible = true;

lbtnFirst.Visible = true;

lbtnLast.Visible = true;



lblStatus.Text =Page+ Convert.ToString(CurrentPage + 1)+of+ Convert.ToString(pds.PageCount);



}



else {



lbtnPrev.Visible = false;

lbtnNext.Visible = false;

lbtnFirst.Visible = false;

lbtnLast.Visible = false;



}



lbtnPrev.Enabled =!pds.IsFirstPage;

lbtnNext.Enabled =!pds.IsLastPage;

lbtnFirst.Enabled =!pds.IsFirstPage;

lbtnLast.Enabled =! pds.IsLastPage;



Repeater1.DataSource = pds;

Repeater1.DataBind();



返回计数;



}

public int当前页面

{

get

{

object obj = this.ViewState [_ CurrentPage]; if(obj == null){return 0; }

else

{

return(int)obj;



}



}







{



//在viewstate中设置当前页码



this.ViewState [_ CurrentPage] =值;



}

}



protected void lbtnPrev_Click(object发件人,EventArgs e)



{



当前页面= = 1;



FillRepeater();



}



protected void lbtnNext_Click(对象发件人,EventArgs e)

{



当前页+ = 1;



FillRepeater();



}



protected void lbtnFirst_Click(object sender,EventArgs e)



{



CurrentPage = 0;



FillRepeater();



}



protected void lbtnLast_Click(object sender,EventArgs e)



{



CurrentPage = FillRepeater() - 1;



FillRepeater();



}

}





我收到语法错误而不是运行时错误,但我不知道如何解决它。请告诉我我在哪里犯错

解决方案

 CurrentPage = FillRepeater() -   1 ; 



减号对我来说很可疑;应该是:

 CurrentPage = FillRepeater() -   1 ; 


The error is in first statement of last method of this code i.e. "CurrentPage = FillRepeater() – 1;" For paging purpose we will use PagedDataSource class which is the same class used for paging in other databound controls.In FillRepeater() I created the object of the PagedDataSource class and utilizes some of its methods.After this simple property used to get the current page value as follows. This simply uses the viewstate to store the current state of the Data page. And also I will add functionality to linkbutton which gets First, Last, Previous and Next page on click event as shown below.

What I have tried:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;

public partial class ExamPage : System.Web.UI.Page
{

SqlConnection con;
string query;


public ExamPage()
{
con = new SqlConnection();
con.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();

}


protected void Page_Load(object sender, EventArgs e)
{

}

private int FillRepeater()
{
query = "select top 10 Question,Option1,Option2,Option3,Option4 from Questions";
SqlCommand cmd = new SqlCommand(query, con);
con.Open(); SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();

da.Fill(ds);

PagedDataSource pds = new PagedDataSource();
pds.DataSource = ds.Tables[0].DefaultView;
pds.AllowPaging = true; pds.PageSize = 8;

int count = pds.PageCount;
pds.CurrentPageIndex = CurrentPage;

if (pds.Count > 0)
{

lbtnPrev.Visible = true;
lbtnNext.Visible = true;
lbtnFirst.Visible = true;
lbtnLast.Visible = true;

lblStatus.Text = "Page " + Convert.ToString(CurrentPage + 1) + "of" + Convert.ToString(pds.PageCount);

}

else {

lbtnPrev.Visible = false;
lbtnNext.Visible = false;
lbtnFirst.Visible = false;
lbtnLast.Visible = false;

}

lbtnPrev.Enabled = !pds.IsFirstPage;
lbtnNext.Enabled = !pds.IsLastPage;
lbtnFirst.Enabled = !pds.IsFirstPage;
lbtnLast.Enabled = !pds.IsLastPage;

Repeater1.DataSource = pds;
Repeater1.DataBind();

return count;

}
public int CurrentPage
{
get
{
object obj = this.ViewState["_CurrentPage"]; if (obj == null) { return 0; }
else
{
return (int)obj;

}

}

set

{

//set in viewstate the current page number

this.ViewState["_CurrentPage"] = value;

}
}

protected void lbtnPrev_Click(object sender, EventArgs e)

{

CurrentPage -= 1;

FillRepeater();

}

protected void lbtnNext_Click(object sender, EventArgs e)
{

CurrentPage += 1;

FillRepeater();

}

protected void lbtnFirst_Click(object sender, EventArgs e)

{

CurrentPage = 0;

FillRepeater();

}

protected void lbtnLast_Click(object sender, EventArgs e)

{

CurrentPage = FillRepeater() – 1;

FillRepeater();

}
}


I am getting syntax error not run-time error but I don't know how to solve it. Please tell me where I am making mistake

解决方案

CurrentPage = FillRepeater() – 1;


The minus sign looks suspicious to me; should be:

CurrentPage = FillRepeater() - 1;


这篇关于我收到一个错误,不知道我不知道如何解决它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆