Devexpress网格视图问题

发布于 2024-10-13 08:01:17 字数 2485 浏览 2 评论 0原文

当我在绑定 gridview 之前访问数据库时 gridview 不再绑定 这里有一些代码:

    void Page_Load(object sender, EventArgs e)
{ 
    if (!IsPostBack)
    {
        date.Date = DateTime.Now;
        string mode = Request.Params["mode"].ToString().ToLowerInvariant();
        lblPatientName.Text= Session["PatientName"].ToString();
        switch (mode)
        {
            case "new":
                {
                    Page.Title = "Add New Patient Visit";

                    Session["visitID"] = System.Guid.NewGuid();

                    //get basic data (countrycode,cityCode,districtCode,areaCode) from patientdata table
                    SqlParameter pra = new SqlParameter("@Patientid", Session["PatientID"].ToString());
                    SqlDataReader dr = SqlHelper.ExecuteReader(ConfigurationManager.ConnectionStrings["NetCareConnectionString"].ConnectionString,
                           "PatientPrescriptionInsertPrepare", pra);

                    if (dr.Read())
                    {
                        SqlParameter[] prm = new SqlParameter[7];

                        prm[0] = new SqlParameter("@visitID", Session["visitID"].ToString());
                        prm[1] = new SqlParameter("@Patientid", Session["PatientID"].ToString());
                        prm[2] = new SqlParameter("@Specialization", Session["special"].ToString());
                        prm[3] = new SqlParameter("@countrycode", dr["CountryCode"].ToString());
                        prm[4] = new SqlParameter("@cityCode", dr["CityCode"].ToString());
                        prm[5] = new SqlParameter("@districtCode", dr["DistrictCode"].ToString());
                        prm[6] = new SqlParameter("@areaCode", dr["AreaCode"].ToString());
                        SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, "PreparePrescrption", prm);
                    }

                }
                break;
        }

    }
}  

当我使用事件绑定网格时,当我删除上面的代码时,一切都运行良好:

 protected void btnAdd_Click(object sender, EventArgs e)
{

    SqlParameter [] prm = new SqlParameter[3];
    prm[0] = new SqlParameter("@visitID", Session["visitID"].ToString());
    prm[1] = new SqlParameter("@Patientid", Session["PatientID"].ToString());
    prm[2] = new SqlParameter("@examinationcode", Session["Examinationcode"].ToString());
    SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, "PatientExaminations_insert", prm);
    gvParientInvs.DataBind();
}

when i access on database before binding the gridview
the gridview never binding again
here some code:

    void Page_Load(object sender, EventArgs e)
{ 
    if (!IsPostBack)
    {
        date.Date = DateTime.Now;
        string mode = Request.Params["mode"].ToString().ToLowerInvariant();
        lblPatientName.Text= Session["PatientName"].ToString();
        switch (mode)
        {
            case "new":
                {
                    Page.Title = "Add New Patient Visit";

                    Session["visitID"] = System.Guid.NewGuid();

                    //get basic data (countrycode,cityCode,districtCode,areaCode) from patientdata table
                    SqlParameter pra = new SqlParameter("@Patientid", Session["PatientID"].ToString());
                    SqlDataReader dr = SqlHelper.ExecuteReader(ConfigurationManager.ConnectionStrings["NetCareConnectionString"].ConnectionString,
                           "PatientPrescriptionInsertPrepare", pra);

                    if (dr.Read())
                    {
                        SqlParameter[] prm = new SqlParameter[7];

                        prm[0] = new SqlParameter("@visitID", Session["visitID"].ToString());
                        prm[1] = new SqlParameter("@Patientid", Session["PatientID"].ToString());
                        prm[2] = new SqlParameter("@Specialization", Session["special"].ToString());
                        prm[3] = new SqlParameter("@countrycode", dr["CountryCode"].ToString());
                        prm[4] = new SqlParameter("@cityCode", dr["CityCode"].ToString());
                        prm[5] = new SqlParameter("@districtCode", dr["DistrictCode"].ToString());
                        prm[6] = new SqlParameter("@areaCode", dr["AreaCode"].ToString());
                        SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, "PreparePrescrption", prm);
                    }

                }
                break;
        }

    }
}  

when i use the event to binding the grid nothing happen when i remove the code upper there every thing run fine:

 protected void btnAdd_Click(object sender, EventArgs e)
{

    SqlParameter [] prm = new SqlParameter[3];
    prm[0] = new SqlParameter("@visitID", Session["visitID"].ToString());
    prm[1] = new SqlParameter("@Patientid", Session["PatientID"].ToString());
    prm[2] = new SqlParameter("@examinationcode", Session["Examinationcode"].ToString());
    SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, "PatientExaminations_insert", prm);
    gvParientInvs.DataBind();
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一抹淡然 2024-10-20 08:01:17

您应该调用 ASPxGridView 的 DataBind 方法来强制网格从底层数据源获取数据。另外,如果您在运行时设置 ASPxGridView 的数据源,则应该在每次向服务器发出请求时执行此操作,如

为什么分页(排序、分组、过滤)在 ASPxGridView 中不起作用?

文章。

You should call the ASPxGridView's DataBind method to force the grid to fetch data from the underlying DataSource. Also, if you set the ASPxGridView's DataSource at runtime, you should do this at every request to the server as it is explained in the

Why might paging (sorting, grouping, filtering) not work in the ASPxGridView?

article.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文