调用SelectedIndexChanged时GridView为空 [英] Gridview empty when SelectedIndexChanged called

查看:89
本文介绍了调用SelectedIndexChanged时GridView为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个DataGrid,它已动态绑定到数据库查询.用户在文本字段中输入一些搜索文本,单击搜索,然后后面的代码使用LINQ创建适当的数据库查询(基于字符串搜索表并返回一组有限的列).

I have a DataGrid which is being bound dynamically to a database query. The user enters some search text into a text field, clicks search, and the code behind creates the appropriate database query using LINQ (searches a table based on the string and returns a limited set of the columns).

然后将GridView数据源设置为查询并调用DataBind().

It then sets the GridView datasource to be the query and calls DataBind().

protected void btnSearch_Click(object sender, EventArgs e)
{
    var query = from record in DB.Table
                where record.Name.Contains(txtSearch.Text) //Extra string checking etc. removed.
                select new
                {
                    record.ID,
                    record.Name,
                    record.Date
                };

    gvResults.DataSource = query;
    gvResults.DataBind();
}

这很好.

当用户在网格中选择一行时,SelectedIndexChanged事件处理程序从网格中的行(字段之一)获取ID,从数据库中查询完整记录,然后填充一组编辑器/详细信息字段记录的全部详细信息.

When a user selects a row in the grid, the SelectedIndexChanged event handler gets the id from the row in the grid (one of the fields), queries the full record from the DB and then populates a set of editor / details fields with the records full details.

protected void gvResults_SelectedIndexChanged(object sender, EventArgs e)
{
    int id = int.Parse(gvResults.SelectedRow.Cells[1].Text);
    DisplayDetails(id);
}

这在我正在开发代码的本地计算机上正常工作.但是,在生产服务器上,该函数已成功调用,但是gvResults上的行和列计数,griview为0-表为空.

This works fine on my local machine where I'm developing the code. On the production server however, the function is called successfully, but the row and column count on gvResults, the griview is 0 - the table is empty.

Gridview的viewstate已启用,我看不出明显的区别.我是否做出过一些天真的假设,或者我依赖的是可能在调试中进行不同配置的内容?

The gridview's viewstate is enabled and I can't see obvious differences. Have I made some naive assumptions, or am I relying on something that is likely to be configured differently in debug?

在本地,我正在VS2008中运行一个空的asp.net Web项目,以加快开发速度.生产服务器正在运行Sitecore CMS,因此配置有所不同.

Locally I am running an empty asp.net web project in VS2008 to make development quicker. The production server is running the sitecore CMS so is configured rather differently.

任何想法或建议都将受到欢迎.预先感谢!

Any thoughts or suggestions would be most welcome. Thanks in advance!

推荐答案

在Sitecore论坛上进行了更多讨论,我遇到了

Having poked around the sitecore forums some more, I came across this blog post explaining one potential solution.

我在Web.config的<typesThatShouldNotBeExpanded>部分中添加了<type>System.Web.UI.WebControls.GridView</type>,它似乎对我们有用.

I added <type>System.Web.UI.WebControls.GridView</type> to the <typesThatShouldNotBeExpanded> section of Web.config and it seems to work for us.

这似乎与sitecore的页面布局渲染管道有关,在该管道中,它扩展了子布局和内部占位符以生成完整的页面渲染.它会访问页面上的.Net控件并对其稍加戳戳,这可能会导致某些控件无法正常工作.

It seems to be to do with sitecore's page layout rendering pipeline, where it expands sub-layouts and internal placeholders to generate the full page rendering. It accesses the .Net controls on the page and pokes them around a bit, which can cause some controls to not work correctly.

有一个文章关于此的 SDN ,尽管只有拥有足够特权帐户的用户才能阅读.希望这将来能对其他Sitecore用户有所帮助.

There is an article on the SDN about this, although you can only read it if you have an account with sufficient privalegs. Hope this might help any other sitecore users out there in future.

这篇关于调用SelectedIndexChanged时GridView为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆