【问题标题】:asp.net gridview null when running on IIS在 IIS 上运行时,asp.net gridview null
【发布时间】:2015-06-30 21:58:59
【问题描述】:

所以,我有一个基于数据库数据的GridView CheckBox column 在一个asp.net 网站。 用户可以检查checkbox,然后我将更改保存到数据库。

在本地一切都很好。但是,当我将网站发布到 IIS 服务器时 - 这就是问题开始的时候 - 在事件查看器中,当用户尝试保存他的更改时,我不断收到以下异常:Index was out of range. Must be non-negative and less than the size of the collection.Parameter name: index 这意味着当试图保存它时,gridview 是空的。 现在,我读了一点,显然PostBack GridView DataSource 并没有保持他的价值观。那么,当我在本地运行网站时,它怎么能完美运行呢?不仅如此-我在网上看到了很多做同样事情的例子,并且对他们有用,例如gridView with checkBox.

我的代码:

网格视图:

<asp:GridView runat="server" ID="grdDataBuffer" Visible="true" >
  <Columns>
   <asp:TemplateField>
   <ItemTemplate>
   <asp:CheckBox ID="CheckBoxColumnDb" runat="server" HeaderText="check" ReadOnly="True"/>
   </ItemTemplate>
   </asp:TemplateField>
 </Columns>
</asp:GridView>

保存按钮:

 <asp:Button ID="btnUpdate" class="Common_Button" runat="server" Text="update" OnClick="btnUpdate_Click" Visible="false"/>

后面的代码:

protected void Page_Load(object sender, EventArgs e)
{   if (!IsPostBack)
    {
        grdDataBuffer.DataSource = null;
        grdDataBuffer.DataBind();
        dv = BL.Process_BL.GetInfo;
        grdDataBuffer.DataSource = dv;
        grdDataBuffer.DataBind();
     }
 }

protected void btnUpdate_Click(object sender, EventArgs e)
{
    //ON IIS SERVER  grdDataBuffer.Rows.Count = 0- ALWAYS!
    for (int i = 0; i < grdDataBuffer.Rows.Count; i++) 
    {
        CheckBox chk =(CheckBox)grdDataBuffer.Rows[i].Cells[0].Controls[1];
        if (chk.Checked == true)
        {
           //does the whole logic and saves it
        }
    }
}

有人吗? 在此先感谢:)

【问题讨论】:

  • 您能分享您的代码以便我们查看问题所在吗?
  • 您是否更新了 Web.Config 中的 SQL 连接字符串? (如果你有的话)。
  • 您的事件查看器中是否显示任何错误? IIS 上是否启用了所有功能?通过 Visual Studio 运行时,IIS Express(VS 使用)的配置与常规 IIS 不同。您的 web.config 是否指向正确的位置?
  • 我们需要你绑定 grdDataBuffer 的代码
  • @user1666620 我的事件查看器没有错误,并且 web.config 指向正确的位置

标签: c# asp.net iis gridview checkbox


【解决方案1】:

有史以来最奇怪的事情——我重新创建了包含所有控件和代码的 asp 页面,一切正常——我猜是旧页面设计器中的一些东西堆积起来,把整个事情搞砸了..

我不知道它是否对任何人有帮助——但有时当假设可行的事情不起作用时——也许值得检查一下设计师是否发生了变化。

【讨论】:

    猜你喜欢
    • 2016-03-29
    • 2023-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多