如何将gridview组标题值插入数据库?

时间:2012-03-14 15:48:55

标签: asp.net

我有一个带有组头的网格视图。我需要将gridview值插入到数据库中。除了组标题值之外,所有内容都会被插入。谁能帮帮我吗?如何将组标题值插入DB?

protected void Btn_Insert_Click(object sender, EventArgs e)
{                      
    foreach (GridViewRow gvr in GridView3.Rows)   //loop through GridView
    {
        SqlConnection con = new SqlConnection("");
        if (gvr.RowType == DataControlRowType.DataRow)
        {
            string qry = "INSERT INTO [] ([ID],[ResourceType],[ResourceDetails],[Rota],[ChargeoutType],[Quantity], [Duration],[UOM], [ChargeRate]) VALUES ('" + test_id.Text.ToString() + "','" + gvr.Cells[1].Text + "','" + gvr.Cells[2].Text + "','" + gvr.Cells[3].Text + "','" + gvr.Cells[4].Text + "','" + gvr.Cells[5].Text + "','" + gvr.Cells[6].Text + "','" + gvr.Cells[7].Text + "','" + gvr.Cells[8].Text + "')";

            SqlCommand com = new SqlCommand(qry, con);
            con.Open();
            com.ExecuteNonQuery();
            con.Close();
        }

ResourceTypeGridView行标题。

GridViewHelper helper = new GridViewHelper(GridView3);

helper.RegisterGroup("ResourceType", true, true);
helper.ApplyGroupSort();

0 个答案:

没有答案