如何在选定的复选框列表的基础上从数据库中获取数据? [英] How to fetch data form the database on the bases of selected checkbox list?

查看:61
本文介绍了如何在选定的复选框列表的基础上从数据库中获取数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好...

我非常需要您的帮助...我目前正在我的大学项目学生反馈系统"上工作...我们有多个选修科目,学生必须从中选择2,3个或任意数量的选修科目... i通过从数据库中获取所有选修科目来显示所有选修科目...学生将从那些选修科目中进行选择...在选择的基础上,将显示反馈页面.

例如:-如果有3个选修科目,例如AI,IP和.NET,并且学生从复选框列表中选择两个选修科目.NET和IP ...则将显示这两个科目的反馈页面...但是在查询中,我只能发送1个选定的主题,并且仅显示1个选修主题反馈页面...

我也要附加代码.

请帮我解决这个问题,否则我的老师会杀了我... !!!

hi everyone...

i need your help very desperately...i am currently working on my college project "Student Feedback System"...we have multiple elective subjects from which a student have to choose 2,3 or any number of elective subject...i displayed all elective subject by fetching them from the database...and the student will select from those elective subject...on the bases of selection the feedback pages are to be displayed..

for example:- if there are 3 elective subjects let say AI,IP and .NET and a student select two elective subject .NET and IP from checkbox list...the feedback page of both the subject are to be displayed...but in the query i am able to send only 1 selected subject and it display only 1 elective subject feedback page...

i am attaching the code also..

Please help me out on this otherwise my faculty gonna kill me...!!!

public partial class Student_Select_Info : System.Web.UI.Page
{
    SqlConnection con;
    
    public string s3;
    
    int i;
    protected void Page_Load(object sender, EventArgs e)
    {
        con = new SqlConnection(ConfigurationManager.ConnectionStrings["SFS"].ConnectionString);
    }
    Class1 chk = new Class1();
    DataSet fd;
    
    protected void Button1_Click(object sender, EventArgs e)
    {        
        fd = chk.dis_diplay("select facultyid,facultyname,coursename,BranchName,subject,year,semester,section,pic from Faculty_Details where CourseName='" + RadioButtonList1.Text + "' and BranchName='" + ViewState["brach"].ToString() + "' and year='" + DropDownList3.Text + "' and semester='" + DropDownList4.Text + "' and section='" + DropDownList5.Text + "' and Subject='" + CheckBoxList1.SelectedItem.Text+ "' or Regulation='Practical' or Regulation='Regular'");
     
            Session["fid"] = fd;
            Server.Transfer("~/Student/Feedback.aspx");   
            
       
    }
    protected void RadioButtonList2_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
    SqlDataReader sqdr, sqdr1, sqldr2;
    ipinfo ob = new ipinfo();
    protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        try
        {
            DropDownList1.Items.Clear();
            DropDownList3.Items.Clear();
            DropDownList4.Items.Clear();
            DropDownList5.Items.Clear();
            
            CheckBoxList1.Items.Clear();
            DropDownList3.Items.Insert(0, "Select");
            DropDownList1.Items.Insert(0, "Select");
            DropDownList4.Items.Insert(0, "Select");
            DropDownList5.Items.Insert(0, "Select");
            
            
             
            sqdr = ob.drop_disp("select distinct(branch_name) from new_branch where course_name='" + RadioButtonList1.SelectedItem.Text + "'");
            sqdr1 = ob.drop_disp("select course_name,branch_name from new_branch where course_name='" + RadioButtonList1.SelectedItem.Text + "'");

            sqdr1.Read();
            string cn = sqdr1["course_name"].ToString();
            vew = sqdr1["branch_name"].ToString();
            if (cn == vew)
            {
                Label11.Text = vew;
                ViewState["brach"] = vew;
                Label11.Visible = true;
                DropDownList1.Visible = false;
            }
            else
                {
            {
                while (sqdr.Read())                                      
                    DropDownList1.Items.Add(sqdr[0].ToString());
                    DropDownList1.Visible = true;
                    Label11.Visible = false;
                }
                vew=DropDownList1.SelectedItem.Text;
                ViewState["brach"] = vew;
            }
            sqdr1.Close();
            sqdr.Close();
            con.Close();


            
            sqldr2 = ob.drop_disp("select Year from Course_Name where [Course Name]='" + RadioButtonList1.SelectedItem.Text.Trim() + "'");
            sqldr2.Read();
            int yr = Convert.ToInt32(sqldr2[0]);


            for (i = 1; i <= yr; i++)
            {
                DropDownList3.Items.Add(i.ToString());
            }

        }
        catch (Exception)
        {
            ClientScript.RegisterStartupScript(GetType(), "Onload", "alert('Abnormal Termination')", true);
        }
    }
    
    ipinfo obj = new ipinfo();
    Class1 cll = new Class1();
    Class1 cll1 = new Class1();
    protected void DropDownList4_SelectedIndexChanged(object sender, EventArgs e)
    {        
        DropDownList5.Items.Clear();
        
        CheckBoxList1.Items.Clear();        
        DropDownList5.Items.Insert(0, "Select");
        
        
        try
        {
            string section = (string)cll.execute_scaler("select [section] from section where semester=" + DropDownList4.SelectedItem.Text.Trim() + "");
            int str = int.Parse(section);
            DropDownList5.Items.Clear();
            DropDownList5.Items.Insert(0, "Select");
            for (int i = 1; i <= str; i++)
            {
                DropDownList5.Items.Add(sec.ExcelColumnFromNumber(i));
            }
        }
        catch (Exception)
        {
            ClientScript.RegisterStartupScript(GetType(), "Onload", "alert('Abnormal Termination')", true);
        }
    }
    protected void DropDownList3_SelectedIndexChanged(object sender, EventArgs e)
    {
        try
        {            
            DropDownList4.Items.Clear();
            DropDownList5.Items.Clear();
            
            CheckBoxList1.Items.Clear();            
            DropDownList4.Items.Insert(0, "Select");
            DropDownList5.Items.Insert(0, "Select");
            
            

            if (DropDownList3.SelectedItem.Text == "1")
            {
                for (int i = 1; i < 3; i++)
                {
                    DropDownList4.Items.Add(i.ToString());
                }
            }
            if (DropDownList3.SelectedItem.Text == "2")
            {
                for (int i = 3; i < 5; i++)
                {
                    DropDownList4.Items.Add(i.ToString());
                }
            }
            if (DropDownList3.SelectedItem.Text == "3")
            {
                for (int i = 5; i < 7; i++)
                {
                    DropDownList4.Items.Add(i.ToString());
                }
            }
            if (DropDownList3.SelectedItem.Text == "4")
            {
                for (int i = 7; i < 9; i++)
                {
                    DropDownList4.Items.Add(i.ToString());
                }
            }
            
        }
        catch (Exception)
        {
            ClientScript.RegisterStartupScript(GetType(), "Onload", "alert('Abnormal Termination')", true);
        }
    }
    string vew;
    protected void DropDownList5_SelectedIndexChanged(object sender, EventArgs e)
    {        
        
        CheckBoxList1.Items.Clear();        
        
        
        if (DropDownList1.SelectedItem.Text != null && DropDownList1.SelectedItem.Text!="Select")
        {
            vew = DropDownList1.SelectedItem.Text;
        }
        else if (Label11.Text != null)
        {
            vew = Label11.Text;
        }
        DataSet ds_sub = cll.dis_diplay("select subject_name from subject_details where branch_name='" + vew+ "' and year=" + DropDownList3.SelectedItem.Text + " and semester='" + DropDownList4.SelectedItem.Text + "'and section='" + DropDownList5.SelectedItem.Text + "' and regulation='Elective'");
       for (int j = 0; j < ds_sub.Tables[0].Rows.Count; j++)
       {
           CheckBoxList1.Items.Add(ds_sub.Tables[0].Rows[j][0].ToString());
       }
      
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        DropDownList1.Items.Clear();
        DropDownList3.Items.Clear();
        DropDownList4.Items.Clear();
        DropDownList5.Items.Clear();
        
        CheckBoxList1.Items.Clear();
        DropDownList1.Items.Insert(0, "Select");
        DropDownList3.Items.Insert(0, "Select");
        DropDownList4.Items.Insert(0, "Select");
        DropDownList5.Items.Insert(0, "Select");
        
        
        Label11.Visible = false;
        DropDownList1.Visible = true;
        RadioButtonList1.SelectedIndex = -1;
    }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        DropDownList3.SelectedIndex = 0;
        DropDownList4.Items.Clear();
        DropDownList5.Items.Clear();
        
        CheckBoxList1.Items.Clear();
               
        DropDownList4.Items.Insert(0, "Select");
        DropDownList5.Items.Insert(0, "Select");
        
        
    }
    

    protected void DropDownList8_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
    //Class1 jj = new Class1();
    protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        //jj.dis_diplay(
       //if(
    }
}

推荐答案


好吧,如果您在SQL语句中遇到的问题(例如如何传递两个pramtter)可能会有所帮助.

Hi ,
well If your problem in SQL statement like how you will pass two pramtter maybe this will help you .

select * from  dbo.Items
where
Item_name  in ( 't-shrit' , 't-shrit4')


这将带来包含这些项目的两行.
最好的问候
M.Mitwalli


this will bring two rows that contains those items .
Best Regards
M.Mitwalli


Re: Multiple Checkbox Values

Dec 08, 2010 04:36 PM|LINK

C# CodeBehind


protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e)

{

Label1.Text = "";

for (int c = 0; c < CheckBoxList1.Items.Count; c++)

{

if (CheckBoxList1.Items[c].Selected)

{

Label1.Text += CheckBoxList1.Items[c].Text;


}

}

}











Asp.net

<asp:CheckBoxList ID="CheckBoxList1" runat="server" AutoPostBack="True"

            onselectedindexchanged="CheckBoxList1_SelectedIndexChanged">
            <asp:ListItem>C#</asp:ListItem>
            <asp:ListItem>Javascript</asp:ListItem>
            <asp:ListItem Value="jlk">C++</asp:ListItem>
            <asp:ListItem></asp:ListItem>
        </asp:CheckBoxList>


这篇关于如何在选定的复选框列表的基础上从数据库中获取数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆