asp.netdropdownlist绑定数据后,提交页面选择的都是第一项,而且绑定 数据是在!ispostback里面写着的
4个回答
2012-03-15
展开全部
private int pageSize = 5;
protected void Page_Load(object sender, EventArgs e)
{
if (this.IsPostBack)
return;
ViewState["pageTotal"] = 0;
ViewState["pageCurrent"] = 0;
BindTogvGoods(Convert.ToInt32(ViewState["pageCurrent"]), pageSize);
BindGoodsInfoByddlPage();
}
private void BindTogvGoods(int pageCurrent, int pageSize)
{
int pageTotal = Convert.ToInt32(ViewState["pageTotal"]);
BLL.GoodsInfo goodsBLL = new BLL.GoodsInfo ();
DataSet ds = goodsBLL.PageChangeGoodsInfoPro (pageCurrent, pageSize, out pageTotal);
this.gvGoods .DataSource = ds;
this.gvGoods.DataBind();
ViewState["pageTotal"] = pageTotal;
if (Convert.ToInt32(ViewState["pageCurrent"]) == 0)
{
this.lbtnFrist .Enabled = false;
this.lbtnPro .Enabled = false;
this.lbtnNext .Enabled = true;
this.lbtnLast .Enabled = true;
}
else if (Convert.ToInt32(ViewState["pageCurrent"]) == Convert.ToInt32(ViewState["pageTotal"]) - 1)
{
this.lbtnFrist.Enabled = true;
this.lbtnPro.Enabled = true;
this.lbtnNext.Enabled = false;
this.lbtnLast.Enabled = false;
}
else
{
this.lbtnFrist.Enabled = true;
this.lbtnPro.Enabled = true;
this.lbtnNext.Enabled = true;
this.lbtnLast.Enabled = true;
}
}
protected void lbtnFrist_Click(object sender, EventArgs e)
{
ViewState["pageCurrent"] = 0;
BindTogvGoods(Convert.ToInt32(ViewState["pageCurrent"]), pageSize);
}
protected void lbtnPro_Click(object sender, EventArgs e)
{
ViewState["pageCurrent"] = Convert.ToInt32(ViewState["pageCurrent"]) - 1;
BindTogvGoods(Convert.ToInt32(ViewState["pageCurrent"]), pageSize);
}
protected void lbtnNext_Click(object sender, EventArgs e)
{
ViewState["pageCurrent"] = Convert.ToInt32(ViewState["pageCurrent"]) + 1;
BindTogvGoods(Convert.ToInt32(ViewState["pageCurrent"]), pageSize);
}
protected void lbtnLast_Click(object sender, EventArgs e)
{
ViewState["pageCurrent"] = Convert.ToInt32(ViewState["pageTotal"]) - 1;
BindTogvGoods(Convert.ToInt32(ViewState["pageCurrent"]), pageSize);
}
protected void ddlPage_SelectedIndexChanged(object sender, EventArgs e)
{
ViewState["pageCurrent"] = Convert.ToInt32(this.ddlPage.SelectedValue);
BindTogvGoods(Convert.ToInt32(ViewState["pageCurrent"]), pageSize);
}
protected void Page_Load(object sender, EventArgs e)
{
if (this.IsPostBack)
return;
ViewState["pageTotal"] = 0;
ViewState["pageCurrent"] = 0;
BindTogvGoods(Convert.ToInt32(ViewState["pageCurrent"]), pageSize);
BindGoodsInfoByddlPage();
}
private void BindTogvGoods(int pageCurrent, int pageSize)
{
int pageTotal = Convert.ToInt32(ViewState["pageTotal"]);
BLL.GoodsInfo goodsBLL = new BLL.GoodsInfo ();
DataSet ds = goodsBLL.PageChangeGoodsInfoPro (pageCurrent, pageSize, out pageTotal);
this.gvGoods .DataSource = ds;
this.gvGoods.DataBind();
ViewState["pageTotal"] = pageTotal;
if (Convert.ToInt32(ViewState["pageCurrent"]) == 0)
{
this.lbtnFrist .Enabled = false;
this.lbtnPro .Enabled = false;
this.lbtnNext .Enabled = true;
this.lbtnLast .Enabled = true;
}
else if (Convert.ToInt32(ViewState["pageCurrent"]) == Convert.ToInt32(ViewState["pageTotal"]) - 1)
{
this.lbtnFrist.Enabled = true;
this.lbtnPro.Enabled = true;
this.lbtnNext.Enabled = false;
this.lbtnLast.Enabled = false;
}
else
{
this.lbtnFrist.Enabled = true;
this.lbtnPro.Enabled = true;
this.lbtnNext.Enabled = true;
this.lbtnLast.Enabled = true;
}
}
protected void lbtnFrist_Click(object sender, EventArgs e)
{
ViewState["pageCurrent"] = 0;
BindTogvGoods(Convert.ToInt32(ViewState["pageCurrent"]), pageSize);
}
protected void lbtnPro_Click(object sender, EventArgs e)
{
ViewState["pageCurrent"] = Convert.ToInt32(ViewState["pageCurrent"]) - 1;
BindTogvGoods(Convert.ToInt32(ViewState["pageCurrent"]), pageSize);
}
protected void lbtnNext_Click(object sender, EventArgs e)
{
ViewState["pageCurrent"] = Convert.ToInt32(ViewState["pageCurrent"]) + 1;
BindTogvGoods(Convert.ToInt32(ViewState["pageCurrent"]), pageSize);
}
protected void lbtnLast_Click(object sender, EventArgs e)
{
ViewState["pageCurrent"] = Convert.ToInt32(ViewState["pageTotal"]) - 1;
BindTogvGoods(Convert.ToInt32(ViewState["pageCurrent"]), pageSize);
}
protected void ddlPage_SelectedIndexChanged(object sender, EventArgs e)
{
ViewState["pageCurrent"] = Convert.ToInt32(this.ddlPage.SelectedValue);
BindTogvGoods(Convert.ToInt32(ViewState["pageCurrent"]), pageSize);
}
展开全部
是说绑定之后默认选中的是第一项,还是说选择了其他选项,提交页面之后总数取到的第一项的值呢?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
这个是页面回发的问题,看来你是!IsPostBack没加对地方了,可以在Page_Load(object sender, EventArgs e)方法里面加上这么一段代码,if(IsPostBack){return;}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询