本文介绍了中继器内的复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我在将按钮的选中的复选框插入选中的复选框中时遇到问题.请帮我.尽快....... 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();
     }
 }

推荐答案

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.


这篇关于中继器内的复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-10 17:47