中继器内的复选框

编程入门 行业动态 更新时间:2024-10-18 19:22:37
本文介绍了中继器内的复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

你好, 我在将按钮的选中的复选框插入选中的复选框中时遇到问题.请帮我.尽快....... plz ....这是我的aspx代码.

Hello, I am facing problem in inserting selected items of checkbox inside repeaters, on button click. please help me. ASAP..........plz....Here is my code of aspx.

<asp:Repeater ID="parent" runat="server" onitemcommand="parent_ItemCommand1"> <ItemTemplate> <b> <asp:CheckBox ID="services1" runat="server" /> <asp:Label ID="lbl" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"BUSINESSUPLOAD_SERVICES_SERVICENAME") %>' /></b><br /> <asp:Repeater ID="child" DataSource='<%# ((DataRowView)Container.DataItem).CreateChildView("myrelation") %>' runat="server"> <ItemTemplate> <asp:CheckBox ID="subservices" runat="server" /> <asp:Label ID="lbl1" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "BUSINESSUPLOAD_SUBSERVICES_SUB_SERVICENAME")%>' /><br> </ItemTemplate> </asp:Repeater> </ItemTemplate> </asp:Repeater> <asp:Button ID="button1" runat="server" Text="submit" CommandName="insert" onclick="button1_Click" />

我的代码在页面后面.

my code behind page.

protected void parent_ItemCommand1(object source, RepeaterCommandEventArgs e) { Label lblserv = new Label(); lblserv = (Label)e.Item.FindControl("lbl"); string txt = lblserv.Text; if (e.CommandName == "insert") ; { SqlConnection con = new SqlConnection("Data Source=USER-PC\\SQLEXPRESS;Initial Catalog=MEDICALVOYAGER;Integrated Security=True"); con.Open(); SqlCommand cmd = new SqlCommand("insert into SERVICES_SELECTED(SERVICESNAME) values(@serv)", con); cmd.Parameters.AddWithValue("@serv", txt); cmd.ExecuteNonQuery(); Response.Write("inserted"); con.Close(); } }

推荐答案

我已经修改了您的代码,并在此处获取CheckBox,如果选中了此复选框,它将保存值 I have modified your and get the CheckBox here, if this checkbox is checked then it will save the values protected void parent_ItemCommand1(object source, RepeaterCommandEventArgs e) { Label lblserv = new Label(); lblserv = (Label)e.Item.FindControl("lbl"); string txt = lblserv.Text; //get the ckeckbox CheckBox chkServ = new CheckBox(); chkServ = (CheckBox)e.Item.FindControl("services1"); if (e.CommandName == "insert") ; { if (chkServ.Checked) { SqlConnection con = new SqlConnection("Data Source=USER-PC\\SQLEXPRESS;Initial Catalog=MEDICALVOYAGER;Integrated Security=True"); con.Open(); SqlCommand cmd = new SqlCommand("insert into SERVICES_SELECTED(SERVICESNAME) values(@serv)", con); cmd.Parameters.AddWithValue("@serv", txt); cmd.ExecuteNonQuery(); Response.Write("inserted"); con.Close(); } } }

您应该为孩子做同样的事情.

you should do same as for the child.

更多推荐

中继器内的复选框

本文发布于:2023-11-25 01:56:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1627840.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:复选框   中继器

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!