如果应用程序非常小并且您没有时间进行编码,那么请使用sql 数据源,因为您不必为此编写一行代码,您也可以非常轻松地使用网格视图插入更新和删除数据。
<asp:GridView ID="GridView1" CssClass="table table-striped table-bordered table-hover" runat="server" AutoGenerateColumns="False" DataKeyNames="UNQ_ID" DataSourceID="SqlDataSource1" EmptyDataText="No Data has been Added." AllowPaging="True" AllowSorting="True">
<Columns>
<asp:CommandField ShowEditButton="True"></asp:CommandField>
<asp:BoundField DataField="UNQ_ID" HeaderText="UNQ_ID" ReadOnly="True" InsertVisible="False" SortExpression="UNQ_ID" Visible="false"></asp:BoundField>
<asp:BoundField DataField="WucsName" HeaderText="WUCS Name" SortExpression="WucsName"></asp:BoundField>
<asp:TemplateField HeaderText="Year" SortExpression="Year_ID">
<EditItemTemplate>
<asp:TextBox runat="server" Text='<%# Bind("Year_ID") %>' ID="TextBox1"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<%#YearCON(int.Parse(DataBinder.Eval(Container.DataItem,"Year_ID" ).ToString()))%>
<%-- <asp:Label runat="server" Text='<%# Bind("Year_ID") %>' ID="Label1"></asp:Label>--%>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Total_Land_Holdings" HeaderText="Total Land Holdings" SortExpression="Total_Land_Holdings"></asp:BoundField>
<asp:BoundField DataField="Former_Paying_Cess" HeaderText="Former Paying Cess" SortExpression="Former_Paying_Cess"></asp:BoundField>
<asp:BoundField DataField="Water_Cess_Collected" HeaderText="Water Cess Collected" SortExpression="Water_Cess_Collected">
</asp:BoundField>
</Columns>
<asp:SqlDataSource runat="server" ID="SqlDataSource1"
ConnectionString='<%$ ConnectionStrings:PMISConnection %>'
SelectCommand="SELECT * FROM [tbl_CWLWRK_WaterCess]"
DeleteCommand="DELETE FROM [tbl_CWLWRK_WaterCess] WHERE [UNQ_ID] = @UNQ_ID" InsertCommand="INSERT INTO [tbl_CWLWRK_WaterCess] ([WucsName], [Year_ID], [Total_Land_Holdings], [Former_Paying_Cess], [Water_Cess_Collected]) VALUES (@WucsName, @Year_ID, @Total_Land_Holdings, @Former_Paying_Cess, @Water_Cess_Collected)" UpdateCommand="UPDATE [tbl_CWLWRK_WaterCess] SET [WucsName] = @WucsName, [Year_ID] = @Year_ID, [Total_Land_Holdings] = @Total_Land_Holdings, [Former_Paying_Cess] = @Former_Paying_Cess, [Water_Cess_Collected] = @Water_Cess_Collected WHERE [UNQ_ID] = @UNQ_ID">
<DeleteParameters>
<asp:Parameter Name="UNQ_ID" Type="Int32"></asp:Parameter>
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="WucsName" Type="String"></asp:Parameter>
<asp:Parameter Name="Year_ID" Type="Int32"></asp:Parameter>
<asp:Parameter Name="Total_Land_Holdings" Type="Int32"></asp:Parameter>
<asp:Parameter Name="Former_Paying_Cess" Type="Int32"></asp:Parameter>
<asp:Parameter Name="Water_Cess_Collected" Type="Int32"></asp:Parameter>
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="WucsName" Type="String"></asp:Parameter>
<asp:Parameter Name="Year_ID" Type="Int32"></asp:Parameter>
<asp:Parameter Name="Total_Land_Holdings" Type="Int32"></asp:Parameter>
<asp:Parameter Name="Former_Paying_Cess" Type="Int32"></asp:Parameter>
<asp:Parameter Name="Water_Cess_Collected" Type="Int32"></asp:Parameter>
<asp:Parameter Name="UNQ_ID" Type="Int32"></asp:Parameter>
</UpdateParameters>
</asp:SqlDataSource>
对于更大的应用程序,您需要使用 Code behind