DataGrid没有更新。 [英] DataGrid not updating.

查看:59
本文介绍了DataGrid没有更新。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个绑定到EntityDataSource的DataGrid。我还有两个TemplateColumns,用于根据行中的数据获得一些结果。当我打开浏览器时,一切正常。当我将文件上传到我的服务器时,数据显示除了两个自定义列保持为空 - 没有错误。什么可能导致这个问题。我正在使用Webforms,计算来自代码隐藏文件。



I have a DataGrid that has bound to an EntityDataSource. I also have two TemplateColumns for some results based on the data in the row. When I open-in-browser all works fine. When I upload the files to my server the data displays except for the two custom columns stay empty - no error either. What could be causing this problem. I''m using Webforms and the calculations come from the code behind file.

<asp:DataGrid ID="dgItems" runat="server" DataSourceID="edsItems" 

            EnableViewState="False" AutoGenerateColumns="False" BackColor="White" 

            BorderColor="#3366CC" BorderStyle="None" BorderWidth="1px" CellPadding="4" >
          <Columns>
              <asp:BoundColumn DataField="Name" HeaderText="Name"></asp:BoundColumn>
              <asp:BoundColumn DataField="Perc" HeaderText="Perc"></asp:BoundColumn>
              <asp:TemplateColumn >
                <HeaderTemplate>
                  <asp:Label ID="lb" runat="server" Text="Dose Type" />
                </HeaderTemplate>
                <ItemTemplate>
                  <asp:Label ID="lbOne" runat="server" Text='<%# Bind("amounts_tb.field1")%>' />
                </ItemTemplate>
              </asp:TemplateColumn>
              <asp:BoundColumn DataField="AmountSupplied" HeaderText="Amount Supplied"></asp:BoundColumn>
              <asp:BoundColumn DataField="VolumeSupplied" HeaderText="Volume Supplied"></asp:BoundColumn>
              <asp:BoundColumn DataField="Max" HeaderText="Max" ></asp:BoundColumn>
              <asp:TemplateColumn >
                <HeaderTemplate>
                  <asp:Label ID="lbAmt" runat="server" Text="Amount" />
                </HeaderTemplate>
                <ItemTemplate>
                  <asp:Label ID="amt" runat="server"  />
                </ItemTemplate>
                </asp:TemplateColumn> 
                <asp:TemplateColumn >
                <HeaderTemplate>
                  <asp:Label ID="lbVol" runat="server" Text="Volume" />
                </HeaderTemplate>
                <ItemTemplate>
                  <asp:Label ID="vol" runat="server"  />
                </ItemTemplate>
                </asp:TemplateColumn> 
          </Columns>
          <FooterStyle BackColor="#99CCCC" ForeColor="#003399" />
          <HeaderStyle BackColor="#003399" Font-Bold="True" ForeColor="#CCCCFF" />
          <ItemStyle BackColor="White" ForeColor="#003399" />
          <PagerStyle BackColor="#99CCCC" ForeColor="#003399" HorizontalAlign="Left" 

              Mode="NumericPages" />
          <SelectedItemStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
      </asp:DataGrid>







Try
      Dim kg As Double
      If Double.TryParse(tbVariable.Text, kg) Then
        For row As Integer = 0 To dgItems.Items.Count - 1
          Dim one, amt, max, amts, vols As Double
          one = CDbl(dgItems.Items(row).Cells(1).Text)
          amts = CDbl(dgItems.Items(row).Cells(3).Text)
          vols = CDbl(dgItems.Items(row).Cells(4).Text)
          max = CDbl(dgItems.Items(row).Cells(5).Text)
          amt = one * kg
          If amt > max Then amt = max
          Dim lbAmt As Label = TryCast(dgItems.Items(row).Cells(6).FindControl("amt"), Label)
          Dim lbVol As Label = TryCast(dgItems.Items(row).Cells(7).FindControl("vol"), Label)
          If Not lbAmt Is Nothing Then lbAmt.Text = Amount(amt, max)
          If Not lbVol Is Nothing Then lbVol.Text = Volume(amt, amts, vols)
        Next
      End If
Catch ex As Exception
      Response.Write(ex.Message)
End Try

推荐答案

您的代码检查查找是否失败,应该如此。你不应该做所有这些,数据绑定应该为你做。只需将数据放入数据源并让数据绑定处理它。或者使用调试器来确定控件查找失败的原因(显然是这样)



此外,数据绑定事件后(在预渲染中),因为否则数据将在事件更改之前加载
Your code checks if the lookup failed, as it should. You should not need to do all this though, the data binding should do it for you. Just put the data in your data source and let data binding take care of it. OR use the debugger to work out why the control lookup fails ( as it clearly does )

Also, data bind AFTER your events ( in prerender ), because otherwise the data will load before it''s changed by an event


这篇关于DataGrid没有更新。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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