C#GridView Datakeys未填充实时环境

问题描述 投票:0回答:0
protected void GridView_Contracts_RowCommand(object sender, GridViewCommandEventArgs e) { if (!Page.IsCallback) { if (e.CommandName == "DETAILS") { int RowIndex = Convert.ToInt32(e.CommandArgument); // following instruction works in localhost, but returns "Index was out of range" on live environment, because GridView_Contracts.DataKeys.Count=0 string sIdContract = GridView_Contracts.DataKeys[RowIndex]["ID_CONTRACT"].ToString(); SES.SetIdContract(sIdContract); Response.Redirect("ContractDetails.aspx", false); } } }

但一旦发布在Live IIS服务器上,此RowCommand事件会产生以下错误:

Index was out of range. Must be non-negative and less than the size of the collection.

其他网站托管在相同的IIS上,并以相同的方式使用相同类型的GridViews&Datakeys,但它们用VB.NET编写。

我没有以怪异的方式调整GridView参数,也没有通过自定义事件或任何其他特殊代码混乱。 triped以故障排除在另一台服务器上发布该应用程序,失败。 depebugging在实时服务器上显示: gridview_contracts.datakeys.count = 0 vs gridview_contracts.datakeys.count = 30 onlocalhost.

我唯一能想到的是与基于零相对于1个基于1的服务器参数有关的事情,因为我们在同一IIS上还有其他一些VB应用程序,但是老实说,我很困惑。你们会知道吗?

非常感谢!

I已从page_load()事件中删除了GridView Databind指令,并且仅在需要时刷新它。它解决了问题。我明白了为什么刷新值可能会与Datakeys混乱,但是我仍然想知道为什么它在Localhost中起作用!

// don't call this sub in the Page_Load() event private void RefreshGridview() { this.SqlDataSource_Contracts.SelectCommand = GetGridviewSql(); this.GridView_Contracts.DataBind(); Label_Gridview.Text = GridView_Contracts.Rows.Count + " contracts in the database"; }

gridview
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.