我在下拉列表中有问题 [英] i have a problem in drop down list

查看:74
本文介绍了我在下拉列表中有问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个下拉列表,其中的源代码是

i have a drop down which source code is

<asp:DropDownList ID="DropDownList1" runat="server"

                   onselectedindexchanged="DropDownList1_SelectedIndexChanged"

                   AutoPostBack="True">
                   <asp:ListItem> --Select--</asp:ListItem>
                   <asp:ListItem> ClientName</asp:ListItem>
                   <asp:ListItem> DeliveryDate</asp:ListItem>
                   <asp:ListItem> ExtendDate</asp:ListItem>



我们选择它运行successfully.but的任何项目时,我们选择然后它给出过程或函数" "预计参数" ",其中未提供.
的错误



we select any item it run successfully.but when we select --select-- then it gives error of Procedure or function ''selectDataByDDLValue'' expects parameter ''@ddlValue'', which was not supplied.

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
      {
          cmd = new SqlCommand(&quot;selectDataByDDLValue&quot; + DropDownList1.SelectedItem.Value.ToString(), con);
          rd = cmd.ExecuteReader();//Procedure or function 'selectDataByDDLValue' expects parameter '@ddlValue', which was not supplied.
          GridView2.DataSource = rd;
          GridView2.DataBind();
          rd.Close();




程序是





procedure is


ALTER PROCEDURE [dbo].[selectDataByDDLValue](@ddlValue varchar(50))
AS
IF @ddlValue = &#39;--select--&#39;
BEGIN
select distinct Fname,Lname from Client_registration_tbl
END
ELSE
BEGIN
IF @ddlValue = &#39;Client Name&#39;
BEGIN
select distinct Fname,Lname from Client_registration_tbl
END
ELSE
BEGIN
  IF @ddlValue = &#39;Delivery Date&#39;
  BEGIN
  select a.Fname,a.Lname, b.Product_name,b.Product_quan,b.Delivery_date  from Client_registration_tbl a , Product_order  b where a.Uname= b.Uname
  END
  ELSE
  BEGIN
  select a.Fname,a.Lname, b.Product_name,b.Product_quan,b.Delivery_date,b.Extend_date  from Client_registration_tbl a , Product_order  b where a.Uname= b.Uname
  END
  END
END

推荐答案

Offcourse --select--不是正确的过滤器值并且应该给出错误,您必须在调用数据库操作之前进行检查

Offcourse --select-- is not a proper filter value and it should give error you have to put a check before calling the DB operations

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
   {
       if (!string.IsNullOrEmpty(DropDownList1.SelectedItem.Value.ToString()))
       {
           cmd = new SqlCommand("selectDataByDDLValue" + DropDownList1.SelectedItem.Value.ToString(), con);
           rd = cmd.ExecuteReader();//Procedure or function 'selectDataByDDLValue' expects parameter '@ddlValue', which was not supplied.
           GridView2.DataSource = rd;
           GridView2.DataBind();
           rd.Close();
       }
   }


检查条件,如果所选项目为SELECT或所选索引为零,则不要执行您的代码.
check with if condition if the selected item is SELECT or selected index is zero than dont execute your code.


亲爱的拉希德,

在检查数据库之前,您可以检查该值.

Dear Rashid,

Before going to check in the database you can check for the value.

if(DropDownList1.selectedIndex!=0)
{
    cmd = new SqlCommand(&quot;selectDataByDDLValue&quot; + DropDownList1.SelectedItem.Value.ToString(), con);
          rd = cmd.ExecuteReader();//Procedure or function 'selectDataByDDLValue' expects parameter '@ddlValue', which was not supplied.
          GridView2.DataSource = rd;
          GridView2.DataBind();
          rd.Close();
}



请检查并解决问题.

感谢和问候
苏曼·扎洛迪亚(Suman Zalodiya)



Please check it and make it resolved if it helps.

Thanks and Regards
Suman Zalodiya


这篇关于我在下拉列表中有问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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