3个DDL和1个GRIDVIEW [英] 3 DDL, AND 1 GRIDVIEW

查看:50
本文介绍了3个DDL和1个GRIDVIEW的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用C#在ASP.NET中开发一个Web应用程序,其中有3个DropDownList(ddl)和一个DataGridView.

I am developing a web application in ASP.NET with C# in which I have 3 DropDownList (ddl) and one DataGridView.

ddl1=CS,IT,A,M
ddl2=FIRST,SECOUND,THIRD
ddl3=FIRST S,SECOUND S


if ddl1.selectedvalue="CS" and ddl2.selectedvalue="FIRST" and ddl3.selectedvalue="FIRST S" then

DataGridView将显示谁的老师的科目和姓名" s为此选择教它.
这是我的代码:

DataGridView will show the subjects and name of teachers who''s teach it for this choice.
and this my code:

public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    Label1.Visible = false;
    }
    protected void BtnSearch_Click(object sender, EventArgs e)
    {
        string cc;
        SqlConnection con = obj.getconn();
        SqlCommand c = new SqlCommand("", con);
        c.CommandText = "selectsubjectname from SUBJECT& Teachername from TEACHER";
        con.Open();
        dr = c.ExecuteReader();
        if ((ddlSearchBy.SelectedIndex == 0)&(ddlSearchBy0.SelectedIndex == 0)&(ddlSearchBy1.SelectedIndex == 0))
        {
            cc = "select subjectname from SUBJECT& Teachername from TEACHER  where SECTION NAME = '"+ ddlSearchBy.SelectedIndex
                 "' And YEAR ='" + ddlSearchBy0.SelectedIndex + "'And SEMESTER='" + ddlSearchBy1.SelectedIndex + "' ";
        }
        else
        {
            Label1.Visible = true;
            Label1.Text = "  ** NOT FOUND ** ";
        }
        ds = obj.GetData(cc, "SUBJECT,TEACHER,YEAR,SECTION");
        GridView1.DataSource = ds.row["subjectname from SUBJECT &Teachername from TEACHER"];
        GridView1.DataBind();
        if (GridView1.Rows.Count == 0)
        {
            Label1.Visible = true;
            Label1.Text = "  ** NOT FOUND ** ";
        }
    }




我被困住了,因为我不知道哪里出错了,请告诉我此代码正确与否




i am stuck , because i dont know where the wrong , plz tell me if this code right or not

推荐答案

在附加的代码中添加try .. catch块为:
Add try.. catch block in the attached code as:
protected void BtnSearch_Click(object sender, EventArgs e)
    {
    try {
      .........
    }
    catch(Exception ex){
      .........
    }



它将指出代码中的确切问题.



It will point out the exact issue in the code.


通过查看您的代码,我可以看到很多问题,其中一些问题如下.请更正这些问题,看看是否仍然收到错误消息?更正后,请按照"GanesanSenthilvel"的建议运行代码.

点1

尝试更改该行[select&您的查询中的使用者名称]

By look at your code, i can see many issues and some of them are as follows. Please correct those issues and see whether you are still getting error messages ? once corrected , please run the code as suggested by "GanesanSenthilvel".

Point 1

Try changing the line [there is no space between select & subjectname in your query ]

c.CommandText = "selectsubjectname from SUBJECT& Teachername from TEACHER";




to

c.CommandText = "select subjectname from SUBJECT, Teachername from TEACHER";



点2

更改以下内容[您需要使用逗号(,)来检索多个列,而不是&]



point 2

Change the following [You needs to use comma(,) to retrieve multiple columns not &]

c = "select subjectname from SUBJECT& Teachername from TEACHER  where SECTION NAME = ''"+ ddlSearchBy.SelectedIndex




to

cc = "select subjectname from SUBJECT,Teachername from TEACHER  where SECTION NAME = ''"+ ddlSearchBy.SelectedIndex



查看其余的代码,并在某些地方使用过&"而不是逗号作为SQL查询列分隔符.


点3

检查行



look at your rest of the code and there are places you have used "&" instead of comma for the SQL query column seperator.


point 3

Check the line

ds = obj.GetData(cc, "SUBJECT,TEACHER,YEAR,SECTION");

...不确定其作用


点4

希望ds是您的数据集,在这种情况下,请更改以下内容

...not sure what it does


point 4

hope ds is you dataset and in that case, change the followings

GridView1.DataSource = ds.row["subjectname from SUBJECT &Teachername from TEACHER"];







to

GridView1.DataSource = ds.table[0].defaultview();


这篇关于3个DDL和1个GRIDVIEW的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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