日期:2014-05-17 浏览次数:20504 次
<asp:GridView ID="GridView1" runat="server" onrowcommand="GridView1_RowCommand"
AutoGenerateColumns="False">
<Columns>
<asp:BoundField DataField="Product" HeaderText="Product" />
<asp:BoundField DataField="Version" HeaderText="Version" />
<asp:BoundField DataField="Description" HeaderText="Description" />
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="Button1" runat="server" Text="Button" CommandArgument="<%# Container.DataItemIndex %>" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.Add("Product", Type.GetType("System.String"));
dt.Columns.Add("Version", Type.GetType("System.String"));
dt.Columns.Add("Description", Type.GetType("System.String"));
DataRow newRow;
newRow = dt.NewRow();
newRow["Product"] = "水果刀";
newRow["Version"] = "2.0";
newRow["Description"] = "打架专用";
dt.Rows.Add(newRow);
newRow = dt.NewRow();