<asp:GridView runat="server" DataKeyNames="ysId" ShowFooter="True" OnRowDataBound="GridView1_RowDataBound" OnRowCreated="GridView1_RowCreated" AutoGenerateColumns="False" CssClass="gridview" EnableModelValidation="True" OnRowCancelingEdit="tabgv_RowCancelingEdit" OnRowEditing="tabgv_RowEditing" OnRowUpdating="tabgv_RowUpdating"> <RowStyle BorderColor="Black" BorderStyle="None" /> <Columns> <asp:BoundField DataField="gsHkrno" HeaderText="项目编号" ReadOnly="True"> <ItemStyle HorizontalAlign="Center" /> <FooterStyle BorderWidth="0px" /> </asp:BoundField> <asp:TemplateField HeaderText="项目名称"> <ItemTemplate> <asp:HyperLink runat="server" ForeColor="Blue" Text='<%# Bind("gsName") %>'></asp:HyperLink> </ItemTemplate> <ItemStyle HorizontalAlign="left" /> <FooterTemplate> <asp:Label runat="server" Font-Bold="True" Text="合 计:"></asp:Label> </FooterTemplate> <FooterStyle BorderColor="Black" BorderWidth="0px" HorizontalAlign="Right" /> </asp:TemplateField> <asp:TemplateField HeaderText="概算金额"> <ItemTemplate> <asp:Label runat="server" Text='<%#Bind("gsMoney", "{0:N2}") %>'></asp:Label> </ItemTemplate> <ItemStyle HorizontalAlign="right" /> <FooterTemplate> <asp:Label runat="server" ForeColor="Red"></asp:Label> </FooterTemplate> <FooterStyle BorderColor="Black" HorizontalAlign="Right" /> </asp:TemplateField> <asp:TemplateField HeaderText="开工至上年底\n累计完成概算"> <ItemTemplate> <asp:Label runat="server" Text='<%# Bind("footMoney", "{0:N2}") %>'></asp:Label> <asp:HiddenField runat="server" Value='<%# Eval("ysYear") %> ' /> <asp:HiddenField runat="server" Value='<%# Eval("gsId") %> ' /> <asp:HiddenField runat="server" Value='<%# Eval("gsHkrno") %> ' /> <asp:HiddenField runat="server" Value='<%# Eval("childFlag") %> ' /> </ItemTemplate> <ItemStyle HorizontalAlign="right" /> <FooterTemplate> <asp:Label runat="server" ForeColor="Red"></asp:Label> </FooterTemplate> <FooterStyle BorderColor="Black" HorizontalAlign="Right" /> </asp:TemplateField> <asp:TemplateField HeaderText="投资计划金额"> <ItemTemplate> <asp:Label runat="server" Text='<%# Bind("tzqysMoney", "{0:N2}") %>'></asp:Label> </ItemTemplate> <EditItemTemplate> <asp:TextBox runat="server" Text='<%# Eval("tzqysMoney") %> ' onKeyPress="if (event.keyCode!=46 && event.keyCode!=45 && (event.keyCode<48 || event.keyCode>57)) event.returnValue=false"></asp:TextBox> </EditItemTemplate> <ItemStyle HorizontalAlign="right" /> <FooterTemplate> <asp:Label runat="server" ForeColor="Red"></asp:Label> </FooterTemplate> <FooterStyle BorderColor="Black" HorizontalAlign="Right" /> </asp:TemplateField> <asp:TemplateField> <ItemTemplate> <asp:Label runat="server" Text='<%# Bind("tzhysMoney", "{0:N2}") %>'></asp:Label> </ItemTemplate> <EditItemTemplate> <asp:TextBox runat="server" Text='<%# Eval("tzhysMoney") %> ' onKeyPress="if (event.keyCode!=46 && event.keyCode!=45 && (event.keyCode<48 || event.keyCode>57)) event.returnValue=false"></asp:TextBox> </EditItemTemplate> <ItemStyle HorizontalAlign="right" /> <FooterTemplate> <asp:Label runat="server" ForeColor="Red"></asp:Label> </FooterTemplate> <FooterStyle BorderColor="Black" HorizontalAlign="Right" /> </asp:TemplateField> <asp:TemplateField HeaderText="备注"> <ItemTemplate> <asp:Label runat="server" Text='<%# Eval("remark") %> '></asp:Label> </ItemTemplate> <EditItemTemplate> <asp:TextBox runat="server" Text='<%# Eval("remark") %> '></asp:TextBox> </EditItemTemplate> <ItemStyle HorizontalAlign="Center" /> </asp:TemplateField> <asp:TemplateField ShowHeader="False"> <EditItemTemplate> <asp:LinkButton runat="server" CausesValidation="True" CommandName="Update" Text="更新"></asp:LinkButton> <asp:LinkButton runat="server" CausesValidation="False" CommandName="Cancel" Text="取消"></asp:LinkButton> </EditItemTemplate> <ItemTemplate> <asp:LinkButton runat="server" CausesValidation="False" CommandName='<%#Eval("childFlag").ToString()== "0" ? "":"Edit"%>' Text='<%#Eval("childFlag").ToString()== "0" ? "锁定":"编辑"%>'></asp:LinkButton> </ItemTemplate> <ItemStyle HorizontalAlign="Center" /> </asp:TemplateField> </Columns> </asp:GridView>
注意:
1、通过设置 ReadOnly="True" 表示此列不可以编辑;
2、通过Text='<%# Bind("tzhysMoney", "{0:N2}") %>'进行金额格式化;
3、重点的编辑\显示\合计