首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

帮小弟我调试以下

2012-01-22 
帮我调试以下protectedvoidbtnprevPage_Click(objectsender,EventArgse){PanelpnlPanelstringstrPanelNam

帮我调试以下
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;

}

热点排行