Gridview问题

时间:2012-07-19 20:50:36

标签: c# asp.net gridview

我正在使用模板来创建gridview。一旦select创建了一个会话变量,我就基本上创建了一个复选框,然后我将用户重定向到一个单独的页面。问题是事件没有触发创建包装器。

活动:

void cmd1_Click(object sender, EventArgs e)
    {

        Button txtdata = (Button)sender;

        inventoryBLL inv = new inventoryBLL();

        GridViewRow gvr = (GridViewRow)txtdata.NamingContainer;

        Label myControl = new Label();

        TableCell tc = gvr.Cells[0];
        // where GridView1 is the id of your GridView and indexOfCell is your index
        foreach (Control c in tc.Controls)
        {
            if (c is Label)
            {
                myControl = (Label)c;
            }
        }
        Label myControl1 = new Label();

        List<string> shipmentnames = new List<string>();
        List<string> asinlist = new List<string>();
        List<string> fnskulist = new List<string>();
        List<string> productlist = new List<string>();
        shipmentnames.Add(inv.shipmentname(_ShipmentID));
        asinlist.Add(myControl.Text);
        asinwrapper asin1 = new asinwrapper(asinlist, fnskulist, productlist, 0);
        asinwrapper.CreateSessionWrapper(asin1);
        ShipmentWrapper.CreateSessionWrapper(new ShipmentWrapper(shipmentnames));

    }

我创建复选框的代码:

                        CheckBox cmd1 = new CheckBox();                           

                        cmd1.Text = "Change";

                        cmd1.CheckedChanged += new EventHandler(cmd1_Click);

                        cmd1.AutoPostBack = true;

                        container.Controls.Add(cmd1);                            

调用模板的代码

            bfield.HeaderTemplate = new GridViewTemplateShipmentItems(ListItemType.Header, "Change", FieldType.Label, ddlShipments.SelectedValue.ToString());

            bfield.ItemTemplate = new GridViewTemplateShipmentItems(ListItemType.Item, "Change", FieldType.ButtonAdd, ddlShipments.SelectedValue.ToString());

            grvList.Columns.Add(bfield);

            bfield = new TemplateField();

1 个答案:

答案 0 :(得分:0)

好的,如果我理解正确,你可以在Gridview的一行中嵌入复选框,对吗?

如果是这样,你必须使用gridview选择的行事件,(复选框事件现在被隐藏,不会按预期运行) 接下来找到复选框 确定是否选中了复选框 重定向用户。

如果你愿意,我可以为你提供更精确的语法。