日期:2014-05-17  浏览次数:20504 次

ASP.NET 如何实现点击按钮后提取出指定GridView某行中各列的值?
现在页面上有一GridView,内有数据若干,每行数据后面有个按钮,点击相应行的按钮之后,将此行每列的值都取出来,存入数据库的某个表中,请问如何实现?我是新手。

------最佳解决方案--------------------

    <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();