有一个简单办法
你在每次调用搜索方法前,先把DataGrid.CurrentPageIndex设置为0;
这样就不会出错了。
你在每次调用搜索方法前,先把DataGrid.CurrentPageIndex设置为0;
这样就不会出错了。
解决方案 »
- 今天总算是碰到了一个诡异的问题关于<%#Eval("")%>
- 提交修改页面后,再进入页面,内容不变的问题
- Asp.net里怎么做视频
- asp.net安装文件制作
- 怎样定按钮的样式?
- 哈哈哈,我的混合型网站终于做好了asp+c#.net
- 关于使用Microsoft Internet Explorer WebControls的问题!
- 运行网上下载的范例代码遇到了问题。
- 怎样把网页上弹出的消息保存到某个控件中
- 找不到类型或命名空间名称“TestSysLib”(是否缺少 using 指令或程序集引用?)???
- 问一个老问题 望大家帮忙!
- 新手的问题--如何作到点击页面中的提交按钮,只刷该页面的DataGrid部分,而其它部分控件值不变?(在线给分)
在搜索按钮的事件里调用索索方法后
你不是要BindData()吗?
就这个前面
public void BindData(){
myconn=new SqlConnection(conn.connstr);
myconn.Open();
mycmd=new SqlCommand("SearchCustomerName",myconn);
mycmd.CommandType=CommandType.StoredProcedure;
SqlParameter prt1=new SqlParameter("@str1",SqlDbType.Char);
prt1.Value=txt1.Text;
mycmd.Parameters.Add(prt1);
SqlParameter prt2=new SqlParameter("@str2",SqlDbType.NVarChar);
prt2.Value=txt2.Text;
mycmd.Parameters.Add(prt2);
myda=new SqlDataAdapter(mycmd);
myds=new DataSet();
myda.Fill(myds,"table1");
mygrid1.DataSource=myds.Tables["table1"];
mygrid1.CurrentPageIndex=0;
mygrid1.DataBind();
}
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;namespace CRM{
public class CONNStr{
public string connstr=ConfigurationSettings.AppSettings["AData"];
}
public class CustomerInfoWeb:System.Web.UI.Page{
public CONNStr conn=new CONNStr();
public SqlConnection myconn;
public SqlCommand mycmd;
public SqlDataAdapter myda;
public DataSet myds;
public DataGrid mygrid1;
public Label label1;
public TextBox txt1,txt2;
public Button button1,button2;
public void DataGrid_PageChanged1(object sender,DataGridPageChangedEventArgs e){
mygrid1.CurrentPageIndex=e.NewPageIndex;
BindData();
int pageNO=mygrid1.CurrentPageIndex+1;
label1.Text="共"+mygrid1.PageCount+"頁,"+mygrid1.PageCount*mygrid1.PageSize+"筆記錄,這是第"+pageNO+"頁";
}
public void button1_click(object sender,System.EventArgs e){
mygrid1.CurrentPageIndex=0;
BindData();
}
public void button2_cancel(object sender,System.EventArgs e){
txt1.Text="";
txt2.Text="";
}
public void BindData(){
myconn=new SqlConnection(conn.connstr);
myconn.Open();
mycmd=new SqlCommand("SearchCustomerName",myconn);
mycmd.CommandType=CommandType.StoredProcedure;
SqlParameter prt1=new SqlParameter("@str1",SqlDbType.Char);
prt1.Value=txt1.Text;
mycmd.Parameters.Add(prt1);
SqlParameter prt2=new SqlParameter("@str2",SqlDbType.NVarChar);
prt2.Value=txt2.Text;
mycmd.Parameters.Add(prt2);
myda=new SqlDataAdapter(mycmd);
myds=new DataSet();
myda.Fill(myds,"table1");
mygrid1.DataSource=myds.Tables["table1"];
mygrid1.DataBind();
}
}
}