ASP.NET GridView绑定数据

<asp:GridView ID="AeroDataListGridView" runat="server" AutoGenerateColumns="False" 
              CellPadding="3" ForeColor="#333333" GridLines="None" 
              onrowdatabound="AeroDataListGridView_RowDataBound" AllowPaging="True" 
              onpageindexchanging="AeroDataListGridView_PageIndexChanging" BackColor="White" 
              BorderColor="Silver" BorderStyle="Ridge" CellSpacing="1" Width="1003px" 
              DataKeyNames="aero_Id" PageSize="20">
              <AlternatingRowStyle BackColor="#E6F7FE" />
            <Columns>
               <asp:TemplateField HeaderText="平台" ItemStyle-Width="80px">
                  <ItemTemplate>
                    
                  </ItemTemplate>
               </asp:TemplateField>
               <asp:TemplateField HeaderText="型号名称">
                  <ItemTemplate>
                     <%#Eval("aero_Name")%>
                  </ItemTemplate>
               </asp:TemplateField>
               <asp:TemplateField HeaderText="在研状态">
                  <ItemTemplate>
                     <%#Eval("state")%>
                  </ItemTemplate>
               </asp:TemplateField>
               <asp:TemplateField HeaderText="总工作量">
                  <ItemTemplate>
                     <%#Eval("workload")%>
                  </ItemTemplate>
               </asp:TemplateField>
               <asp:TemplateField HeaderText="总正式工艺工作量">
                  <ItemTemplate>
                     <%#Eval("planned_step")%>
                  </ItemTemplate>
               </asp:TemplateField>
               <asp:TemplateField HeaderText="总临时工艺工作量">
                  <ItemTemplate>
                     <%#Eval("temp_step")%>
                  </ItemTemplate>
               </asp:TemplateField>
               <asp:TemplateField HeaderText="总工序">
                  <ItemTemplate>
                     <%#Eval("procedure")%>
                  </ItemTemplate>
               </asp:TemplateField>
               <asp:TemplateField HeaderText="总技术问题处理单数量">
                  <ItemTemplate>
                     <%#Eval("question")%>
                  </ItemTemplate>
               </asp:TemplateField>
               <asp:TemplateField HeaderText="总工期">
                  <ItemTemplate>
                     <%#Eval("duration")%>
                  </ItemTemplate>
               </asp:TemplateField>
               <asp:TemplateField HeaderText="日均工作量">
                  <ItemTemplate>
                     <%#Eval("dailywork")%>
                  </ItemTemplate>
               </asp:TemplateField>
               <asp:TemplateField HeaderText="操 作">
                  <ItemTemplate>
                      <asp:LinkButton ID="LinkButton1" runat="server" onclick="LinkButton1_Click">查看</asp:LinkButton>
                  </ItemTemplate>
               </asp:TemplateField>
            </Columns>
              <EditRowStyle BackColor="#2461BF" />
              <FooterStyle BackColor="#B5CAE7" Font-Bold="True" ForeColor="White" />
              <HeaderStyle BackColor="#B5CAE7" Font-Bold="True" ForeColor="White" 
                  HorizontalAlign="Center" />
              <PagerStyle BackColor="#B5CAE7" ForeColor="White" HorizontalAlign="Center" />
              <RowStyle BackColor="#B5CAE7" HorizontalAlign="Center" ForeColor="#305A68" />
              <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
              <SortedAscendingCellStyle BackColor="#F5F7FB" />
              <SortedAscendingHeaderStyle BackColor="#6D95E1" />
              <SortedDescendingCellStyle BackColor="#E9EBEF" />
              <SortedDescendingHeaderStyle BackColor="#4870BE" />
          </asp:GridView>

  protected void AeroDataListGridView_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                AeroData t = (AeroData)e.Row.DataItem;
                string aeroId =  t.aero_Id;
                var re = from tt in context.SRC_DEF_PLATFORM_AEROCRAFT
                         where tt.AEROCRAFT_ID == aeroId
                         select tt;
                if (re.Count() != 0)
                {
                    decimal pId = (re.ToList())[0].PLATFORM_ID;
                    string pName = (context.SRC_DEF_PLATFORM.Where(item => item.PLATFORM_ID == pId)).Single().PLATFORM_NAME;
                    e.Row.Cells[0].Text = pName;
                }
                else
                {
                    e.Row.Cells[0].Text = "";
                }
            }
        }

posted @ 2013-05-13 15:54  louiskoo  阅读(7221)  评论(0编辑  收藏  举报