简体   繁体   English

Gridview问题

[英]Trouble with Gridview

I am using a template to have create my gridview. 我正在使用模板来创建我的gridview。 I have have basically created a check box when once select creates a session variable and I then redirect the user to a separate page. 当选择一次创建会话变量时,我基本上已经创建了一个复选框,然后将用户重定向到单独的页面。 The problem is the that the event is not firing off creating the wrapper. 问题在于事件没有触发创建包装器。

The event: 事件:

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

    }

The code that I create the checkbox: 我创建复选框的代码:

                        CheckBox cmd1 = new CheckBox();                           

                        cmd1.Text = "Change";

                        cmd1.CheckedChanged += new EventHandler(cmd1_Click);

                        cmd1.AutoPostBack = true;

                        container.Controls.Add(cmd1);                            

The code calling the template 调用模板的代码

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

Ok, so if I understood correctly, you have the checkbox embedded in a row of the Gridview, correct? 好的,所以如果我理解正确的话,您将复选框嵌入到Gridview的一行中,对吗?

If so, you have to work with the gridview selected row event, (the checkbox events are now hidden and will not function as expected) next find the checkbox determine if the checkbox is checked redirect the user. 如果是这样,则必须使用gridview选定的行事件(复选框事件现在已隐藏并且将无法按预期运行),接下来找到该复选框,以确定是否选中了该复选框来重定向用户。

I can get you more precise syntax if you like. 如果您愿意,我可以为您提供更精确的语法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM