checkbox自定义生成控件后添加触发事件(取值和设置单选)
前台代码 : //三级联动 <tr> <td style="width: 100px" bgcolor="#f6f5f5" class="bg_05"> 产品类别:</td> <td align="left" bgcolor="#FFFFFF"> <%--<asp:DropDownList ID="ddlType" runat="server" Width="100px" AutoPostBack="True" onselectedindexchanged="ddlType_SelectedIndexChanged"> </asp:DropDownList>--%> <asp:ListBox ID="lbxTypeList1" runat="server" AutoPostBack="True" Height="166px" OnSelectedIndexChanged="lbxTypeList1_SelectedIndexChanged" Width="100px"></asp:ListBox> <asp:ListBox ID="lbxTypeList2" runat="server" AutoPostBack="True" Height="166px" OnSelectedIndexChanged="lbxTypeList2_SelectedIndexChanged" Width="100px" Visible="False"></asp:ListBox> <asp:ListBox ID="lbxTypeList3" runat="server" AutoPostBack="True" Height="166px" OnSelectedIndexChanged="lbxTypeList3_SelectedIndexChanged" Width="100px" Visible="False"></asp:ListBox> </td> </tr> //自定义添加checkbox控件框架 <asp:Panel ID="Panel5" runat="server"> <table id="Table4" width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#cecece"> <tr> <td style="width:100px" bgcolor="#f6f5f5"> 关联属性:</td> <td align="left" bgcolor="#FFFFFF"> <br /> <asp:Panel runat="server" ID="p1" Visible="False"> <asp:Label ID="label1" runat="server" Text="单选"></asp:Label> <br /> </asp:Panel> <br /> <asp:Panel runat="server" ID="p2" Visible="False"> <asp:Label ID="label2" runat="server" Text="多选"></asp:Label> <br /> </asp:Panel> <br /> <asp:Panel runat="server" ID="p3" Visible="False"> <asp:Label ID="Label3" runat="server" Text="文本"></asp:Label> <br /> <asp:TextBox ID="txtText" runat="server"></asp:TextBox> </asp:Panel> </td> </tr> </table> </asp:Panel>//后台代码:根据类别获取类别属性赋值到自定义生成的checkbox里面 //属性又分为三种单选、多选以及文本
private void bindCkeck(string categoryID) { DataTable dt = ptManager.selectCA("a.categoryID=" + categoryID + " AND c.languageID=" + this.ddlLanguage.SelectedValue).Tables[0]; string data = ""; string attID = ""; int typeID1 =0; int typeID2 =0; int typeID3 =0 ; if (dt.Rows.Count > 0 && dt != null) { this.Panel5.Visible = true; for (int i = 0; i < dt.Rows.Count; i++) { if (dt.Rows[i]["type"].ToString() == "1") { typeID1 = 1; } if (dt.Rows[i]["type"].ToString() == "2") { typeID2 = 2; } if (dt.Rows[i]["type"].ToString() == "3") { typeID3 = 3; } } if (typeID1 == 1) { DataTable dt1 = ptManager.selectCA("a.categoryID=" + categoryID + " AND c.languageID=" + this.ddlLanguage.SelectedValue + " and b.type=1").Tables[0]; this.p1.Visible = true; for (int i = 0; i < dt1.Rows.Count; i++) { attID = dt1.Rows[i]["attributeID"].ToString(); data = dt1.Rows[i]["data"].ToString(); string[] strAtt = attID.Split('|'); string[] strData = data.Split('|'); for (int j = 0; j < strAtt.Length; j++) { if (attID != "") { Label lbl = new Label(); lbl.Text = dt1.Rows[i]["name"].ToString(); lbl.Text += " "; this.p1.Controls.Add(lbl); cbl = new CheckBoxList(); cbl.ID = attID; for (int k = 0; k < strData.Length; k++) { if (strData[i] != "") { cbl.Items.Add(new ListItem(strData[k], k.ToString())); } } } } //cbl.SelectedIndexChanged += new System.EventHandler(CBL_SelectedIndexChanged); //cbl.AutoPostBack = true; this.p1.Controls.Add(cbl); } } else { this.p1.Visible = false; } if (typeID2 == 2) { DataTable dt2 = ptManager.selectCA("a.categoryID=" + categoryID + " AND c.languageID=" + this.ddlLanguage.SelectedValue + " and b.type=2").Tables[0]; this.p2.Visible = true; for (int i = 0; i < dt2.Rows.Count; i++) { attID = dt2.Rows[i]["attributeID"].ToString(); data = dt2.Rows[i]["data"].ToString(); string[] strAtt = attID.Split('|'); string[] strData = data.Split('|'); for (int j = 0; j < strAtt.Length; j++) { if (attID != "") { Label lbl = new Label(); lbl.Text = dt2.Rows[i]["name"].ToString(); lbl.Text += " "; this.p2.Controls.Add(lbl); cbl = new CheckBoxList(); cbl.ID = attID; for (int k = 0; k < strData.Length; k++) { if (strData[i] != "") { cbl.Items.Add(new ListItem(strData[k], k.ToString())); } } } } //cbl.SelectedIndexChanged += new System.EventHandler(this.CheckBoxList1_SelectedIndexChanged); //cbl.AutoPostBack = true; this.p2.Controls.Add(cbl); } } else { this.p2.Visible = false; } if (typeID3 == 3) { DataTable dt3 = ptManager.selectCA("a.categoryID=" + categoryID + " AND c.languageID=" + this.ddlLanguage.SelectedValue + " and b.type=3").Tables[0]; this.p3.Visible = true; for (int i = 0; i < dt3.Rows.Count; i++) { this.txtText.Text += dt3.Rows[i]["data"]; } } else { this.p3.Visible = false; } } else { this.Panel5.Visible = false; } }
求 怎么添加自定义生成的checkbox的时间触发 然后设置单选里面生成的checkbox只能单选,和获取自定义生成的checkbox里面的值 --------------------编程问答-------------------- --------------------编程问答-------------------- 求解释啊 嘿嘿 --------------------编程问答-------------------- 哥哥啊
是个人都不想看啊。。。太晕人了。。 --------------------编程问答-------------------- 不是 啊 其实就是checkbox 从后台生成,然后在前台勾选,我要从后台获取它们的触发事件,限定是否多选单选,然后获取它们的值,有什么好办法吗
补充:.NET技术 , C#