我在百度里搜了一下,用System.Convert.ToInt32可以解决问题,但是不知道在下面的程序里怎么用。大家帮忙看一下
void PagerButtonClick(Object sender, EventArgs e)
{
//获得LinkButton的参数值
String arg = ((LinkButton)sender).CommandArgument; switch (arg)
{
case ("next"):
if (MyDataGrid.CurrentPageIndex < (MyDataGrid.PageCount - 1))
MyDataGrid.CurrentPageIndex++;
break;
case ("prev"):
if (MyDataGrid.CurrentPageIndex > 0)
MyDataGrid.CurrentPageIndex--;
break;
case ("last"):
MyDataGrid.CurrentPageIndex = (MyDataGrid.PageCount - 1);
break;
default:
//本页值
MyDataGrid.CurrentPageIndex = arg.ToInt32();
break;
}
BindGrid();
}
void PagerButtonClick(Object sender, EventArgs e)
{
//获得LinkButton的参数值
String arg = ((LinkButton)sender).CommandArgument; switch (arg)
{
case ("next"):
if (MyDataGrid.CurrentPageIndex < (MyDataGrid.PageCount - 1))
MyDataGrid.CurrentPageIndex++;
break;
case ("prev"):
if (MyDataGrid.CurrentPageIndex > 0)
MyDataGrid.CurrentPageIndex--;
break;
case ("last"):
MyDataGrid.CurrentPageIndex = (MyDataGrid.PageCount - 1);
break;
default:
//本页值
MyDataGrid.CurrentPageIndex = arg.ToInt32();
break;
}
BindGrid();
}
解决方案 »
- GridView的分页问题
- catch 出来的东西 谁能解决????????
- 新建的WebForm,在什么情况下筐架下的菜单可用,我的怎么不能用呢?
- 一个数据更新的问题征求比较好的方案!
- 为什么要限制长度
- javascript插入表情,像QQ那样的,如何实现?
- VS2005自定义命名空间问题
- 我把arrayList绑定到datagrid上,但英文字段名和排序问题困扰着我?
- 急!如何定义一个隐藏的层,点击web页面上一个button让这个层显示出来,然后点击这个层上的一个button让这个层隐藏,怎样做?
- DataGrid分页后的一个问题
- 如何得到上一年的今天
- 一个关于LinkButton的问题,请教
MyDataGrid.CurrentPageIndex = arg.ToInt32();
应该是这样:
MyDataGrid.CurrentPageIndex = Convert.ToInt43(arg);
另外,这种转化最好是用Int.TryParse(arg, MyDataGrid.CurrentPageIndex),这样如果arg不能转化,会返回false,你可以不用再去try,catch
MyDataGrid.CurrentPageIndex = Convert.ToInt32(arg);
改为:MyDataGrid.CurrentPageIndex = int.Parse(arg);
or
MyDataGrid.CurrentPageIndex = Convert.ToInt32(arg);
==============================================
MyDataGrid.CurrentPageIndex = Convert.ToInt32(arg);
报错:
“ASP.printbower2_aspx.MyDataGrid_Page(object, System.Web.UI.WebControls.DataGridPageChangedEventArgs)”是一个“方法”,这在给定的上下文中无效源错误: 行 60: void BindGrid()
行 61: {
行 62: MyDataGrid_Page.DataSource = CreateDataSource();
行 63: MyDataGrid_Page.DataBind();
行 64: ShowStats();
他的CreateDataSource是这样写的:
ICollection CreateDataSource()
{
string strConnection = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" + Server.MapPath("local.mdb") + ";";
string strSQL = "SELECT * FROM MOBILE_CALL_TICKET_ZRY";
OleDbConnection MyConnection = new OleDbConnection(strConnection);
OleDbDataAdapter MyDataSetCommand = new OleDbDataAdapter(strSQL, MyConnection);
DataSet ds = new DataSet();
MyDataSetCommand.Fill(ds, "admin_enter");
return ds.Tables["admin_enter"].DefaultView;
}
我不明白为什么在上下文中无效,请大家指教。
ICollection CreateDataSource()
{
/*
读取数据库的信息,获得DataView
*/
SQLConnection MyConnection = new SQLConnection("server=localhost;uid=sa;pwd=123456;database=aspcn");
SQLDataSetCommand MyDataSetCommand = new SQLDataSetCommand("select * from admin_enter order by Enter_Time desc",MyConnection);
DataSet ds= new DataSet();
MyDataSetCommand.FillDataSet(ds,"admin_enter");
return ds.Tables["admin_enter"].DefaultView;
}
------------------------------------------------
MyDataGrid_Page这是一个事件处理函数把
MyDataGrid.DataSource = CreateDataSource();
MyDataGrid.DataBind();