Click here to Skip to main content
15,885,180 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.NET
<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>


VB
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
Posted
Updated 4-Jan-13 8:57am
v3
Comments
fjdiewornncalwe 4-Jan-13 14:37pm    
There is really no way for us to guess what could be wrong. Show us some relevant code snippets so that we can help you.
GregWyatt 4-Jan-13 15:46pm    
After you set all of the label values in the for loop are you rebinding the gridview to take the updated values? To do this you call the Databind function on the Gridview object.
Idle_Force 4-Jan-13 16:04pm    
I did try that and it does not make any changes. It is just weird how it works on the development server just fine and then nothing on the live one =(
GregWyatt 4-Jan-13 16:15pm    
Can you elaborate on when in the page life cycle these event are taking place? Like page_load vs init or due to a callback event.
Idle_Force 4-Jan-13 16:25pm    
Button click event. It's like the code behind events are not firing.

1 solution

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
 
Share this answer
 
Comments
Idle_Force 4-Jan-13 18:27pm    
I also found it takes a few minutes for my server to be updated after Publish - may have missed some changes. All is good now!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900