如何在gridview列中动态添加按钮?

时间:2017-05-15 07:07:33

标签: c# asp.net gridview

我有这个gridview代码。如何使用此代码启用按钮以在第一列以外的每一行中的所有列中添加?我没有为gridview分配模板字段或其他因为我通过此代码声明gridview显示。我怎么能实现这一目标?这是我的代码:

`protected void Page_Load(object sender, EventArgs e)
{
    //where request_date >= DATEADD(day,-8, GETDATE())
    con.Open();
    DataTable dtTemp = new DataTable();
    cmd = new SqlCommand("SELECT a.request_date,a.prod_line,a.jo_no,a.qty,CONVERT(VARCHAR(10),a.need_by_date ,101) as need_by_date,b.process_id FROM CutPanelCard a LEFT JOIN CutPanelConfirmation b on b.req_id=a.req_id where request_date >= DATEADD(day,-8, GETDATE()) order by request_date", con);
    SqlDataAdapter da = new SqlDataAdapter(cmd);
    da.Fill(dtTemp);

    ViewState["Information"] = dtTemp;

    try
    {


        {
            //DataTable dtTemp = (DataTable)ViewState["Information"];
            DataTable dtDistinctRecords = dtTemp.DefaultView.ToTable(true, "prod_line");
            DataTable dtStudentName = dtTemp.DefaultView.ToTable(true, "request_date");
            DataTable a = new DataTable();


            DataTable dtStudent = new DataTable();

            dtStudent.Columns.Add("request_date");
            foreach (DataRow rows in dtDistinctRecords.Rows)
            {
                dtStudent.Columns.Add(rows["prod_line"].ToString());
            }

            foreach (DataRow row in dtStudentName.Rows)
            {

                DataRow dr = dtStudent.NewRow();
                dr["request_date"] = row["request_date"];
                DataView dv = new DataView(dtTemp);
                dv.RowFilter = "request_date='" + row["request_date"] + "'";
                DataTable dtStudentdtl = dv.ToTable();

                for (int i = 0; i < dtStudentdtl.Rows.Count; i++)
                {

                        string colValue = dtStudentdtl.Rows[i]["jo_no"].ToString();
                        string colValue2 = dtStudentdtl.Rows[i]["qty"].ToString();
                        string colValue3 = dtStudentdtl.Rows[i]["need_by_date"].ToString();
                        string colValue4 = dtStudentdtl.Rows[i]["process_id"].ToString();

                        dr[dtStudentdtl.Rows[i]["prod_line"].ToString()] = "JO: " + colValue + "  Quantity: " + colValue2 + "  Need by Date: " + colValue3 + "  Completion Status: " + colValue4;


                }
                dtStudent.Rows.InsertAt(dr, dtStudent.Rows.Count);

            }


            GridView1.DataSource = dtStudent;
            GridView1.DataBind();
            GridView_Row_Merger(GridView1);
            con.Close();
        }
    }
    catch (Exception ex)
    {
        Response.Write(ex.Message);
    }
}`

0 个答案:

没有答案