我在类中全局设置了数据集属性,如下所示,并在pageload event.so中绑定gridview,如下所示抛出错误 / 值不能为空。 参数名称:dataSet /
公共DataSet Ds
{
得到
{
object temp = ViewState [" Ds"];
return temp == null? null:temp as DataSet;
}
组 {
ViewState [" Ds"] =值;
}
}public void gridCustBind(int pageIndex) { try { //open the db connection if it is closed... if (connection.State == ConnectionState.Closed) connection.Open(); command = new SqlCommand(); command.CommandText = "sp_Get_CustInfoSerach"; command.CommandType = CommandType.StoredProcedure; command.Connection = connection; command.Parameters.AddWithValue("@PageIndex", pageIndex); command.Parameters.AddWithValue("@PageSize", int.Parse(ddlPaging.SelectedValue)); command.Parameters.Add("@RecordCount", SqlDbType.Int, 4); command.Parameters["@RecordCount"].Direction = ParameterDirection.Output; //SqlParameter outParam = command.Parameters.Add("@bal", SqlDbType.Float); //outParam.Direction = ParameterDirection.Output; command.Parameters.Add("@bal", SqlDbType.Int, 4); command.Parameters["@bal"].Direction = ParameterDirection.Output; SqlDataAdapter daAcc = new SqlDataAdapter(command); daAcc.Fill(Ds); } catch (Exception ex) { lblMessageCustSerach.Text = ex.Message; lblMessageCustSerach.Visible = true; } finally //Close db Connection if it is open.... { if (connection.State == ConnectionState.Open) connection.Close(); } } protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack == true) { gridCustBind(1); if (gridCustomer.Rows.Count > 0) { gridCustomer.DataSource = Ds; gridCustomer.DataBind(); } } }