datagrid
DataGrid:
aspx中
<asp:datagrid ID="dg" runat="server" AutoGenerateColumns="False" >
<Columns>
<asp:BoundColumn DataField="id" Visible="False">
</asp:BoundColumn>
<asp:BoundColumn HeaderText="名称" DataField="title">
</asp:BoundColumn>
<asp:BoundColumn HeaderText="个数" DataField="name">
</asp:BoundColumn>
<asp:BoundColumn HeaderText="用途" DataField="contents">
</asp:BoundColumn>
<asp:ButtonColumn ButtonType="LinkButton" CommandName="modify" Text="修改">
</asp:ButtonColumn>
<asp:ButtonColumn ButtonType="LinkButton" CommandName="delete" Text="删除" >
</asp:ButtonColumn>
</Columns>
</asp:datagrid>
cs中
co.con();
SqlDataAdapter adapter = new SqlDataAdapter(sql,co.conn);
DataSet ds = new DataSet();
adapter.Fill(ds,tablename);
dg.DataSource = ds.Tables[tablename];
dg.DataBind();
co.discon();