编辑以编程方式生成的gridview的选项

时间:2013-07-17 07:19:24

标签: c# asp.net gridview dynamic

public void BuildBranches()
{
    DataTable dtBranches = new DataTable();
    divBranches.Controls.Clear();
    objsupplyPL.username = Session["username"].ToString();
    dtBranches = objsupplyBAL.GetBPFEnteredBranches(objsupplyPL);
    if (dtBranches.Rows.Count > 0)
    {
        for (int i = 0; i < dtBranches.Rows.Count; i++)
        {

            DataTable dtIndentDetails = new DataTable();
            string branches = dtBranches.Rows[i]["branch"].ToString();
            objsupplyPL.branch = branches;
            dtIndentDetails = objsupplyBAL.GetStock(objsupplyPL);

            Table tbldynamic = new Table();
            TableRow tr = new TableRow();
            TableCell tc = new TableCell();



            string st = dtBranches.Rows[i]["branch"].ToString();



            GridView gv = new GridView();
            gv.ID = "gv" + dtBranches.Rows[i]["branch"].ToString();
            gv.Width = 500;

            BoundField bfpurchaseid = new BoundField();
            bfpurchaseid.HeaderText = "Productid";
            bfpurchaseid.DataField = "productid";
            gv.Columns.Add(bfpurchaseid);

            BoundField bfProductId = new BoundField();
            bfProductId.HeaderText = "Product Name";
            bfProductId.DataField = "productname";
            gv.Columns.Add(bfProductId);              

            BoundField bfIssue = new BoundField();
            bfIssue.HeaderText = "Issue";
            gv.Columns.Add(bfIssue);

            BoundField bfgrno = new BoundField();
            bfgrno.HeaderText = "Transfer";
            gv.Columns.Add(bfgrno);

            gv.DataKeyNames = new string[]
            {
                "keys","branch"
            };


            gv.RowDataBound += new GridViewRowEventHandler(gv_RowDataBound);
            gv.RowCommand += new GridViewCommandEventHandler(gv_RowCommand);

            gv.AutoGenerateColumns = false;
            gv.EmptyDataText = "No Records Found";
            gv.DataSource = dtIndentDetails;
            gv.DataBind();
            divBranches.Controls.Add(tbldynamic);
            divBranches.Controls.Add(gv);

            LiteralControl @break1 = default(LiteralControl);
            @break1 = new LiteralControl("<br />");
            divBranches.Controls.Add(@break1);

        }
    }
}

动态gridview工作正常。我想给用户提供编辑选项以更新网格

BoundField是否可以更新网格?或者我必须创建Templatefield?。请帮我解决有关动态网格的方法。

0 个答案:

没有答案