实现GridView数据编辑功能:
<span style="font-size: 12pt; font-family: 宋体; mso-ascii-font-family: 'Times New Roman';
mso-hansi-font-family: 'Times New Roman'; mso-bidi-font-family: 'Times New Roman';
mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN;
mso-bidi-language: AR-SA">实现GridView数据编辑功能<br />
<br />
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" AutoGenerateEditButton="True"
DataSourceID="SqlDataSource1" AllowPaging="True" PageSize="5">
<Columns>
<asp:BoundField DataField="StuID" HeaderText="StuID" SortExpression="StuID" />
<asp:BoundField DataField="Stuname" HeaderText="Stuname" SortExpression="Stuname" />
<asp:BoundField DataField="Stuage" HeaderText="Stuage" SortExpression="Stuage" />
<asp:BoundField DataField="Address" HeaderText="Address" SortExpression="Address" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:DatabindControlsConnectionString %>"
SelectCommand="SELECT * FROM [student]" UpdateCommand="update student set Stuname=@Stuname,Stuage=@Stuage,Address=@Address where StuID=@StuID">
</asp:SqlDataSource>
</span>
将GridView某列设置特殊格式:
<div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1">
<Columns>
<asp:BoundField DataField="Stuname" HeaderText="Stuname" SortExpression="Stuname">
<ControlStyle BackColor="#FF8080" BorderColor="Blue" />
<ItemStyle BackColor="Red" BorderColor="#0000C0" BorderStyle="Solid" BorderWidth="2px" />
</asp:BoundField>
<asp:BoundField DataField="Stuage" HeaderText="Stuage" SortExpression="Stuage" />
<asp:BoundField DataField="Address" HeaderText="Address" SortExpression="Address" />
<asp:BoundField DataField="Grade" HeaderText="Grade" SortExpression="Grade" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:DatabindControlsConnectionString %>"
SelectCommand="SELECT [Stuname], [Stuage], [Address], [Grade] FROM [student]"></asp:SqlDataSource>
</div>