当前位置: 代码迷 >> ASP.NET >> 帮小弟我调试以下
  详细解决方案

帮小弟我调试以下

热度:3588   发布时间:2013-02-26 00:00:00.0
帮我调试以下
protected   void   btnprevPage_Click(object   sender,   EventArgs   e)
        {
                Panel   pnlPanel;
                string   strPanelName;

                strPanelName   =   "pnlForm "   +   ViewState[ "CurrentPage "];
                pnlPanel   =   FindControl(strPanelName);
                pnlPanel.Visible   =   false;

                ViewState[ "CurrentPage "]   -= "1 ";
                strPanelName   =   "pnlForm "   +   ViewState[ "CurrentPage "];
                pnlPanel   =   FindControl(strPanelName);
                pnlPanel.Visible   =   true;

        }

------解决方案--------------------------------------------------------
补充,再更正一下:

protected void btnprevPage_Click(object sender, EventArgs e)
{
Panel pnlPanel;
string strPanelName;

strPanelName = "pnlForm " + ViewState[ "CurrentPage "].ToString();

// FindControl返回的类型要强制转换
pnlPanel = (Panel)FindControl(strPanelName);
pnlPanel.Visible = false;

// 需要数值型才能运算
(int)ViewState[ "CurrentPage "] -= 1;
strPanelName = "pnlForm " + ViewState[ "CurrentPage "].ToString();
pnlPanel = (Panel)FindControl(strPanelName);
pnlPanel.Visible = true;

}
  相关解决方案