使用asp.net的下拉菜单中的错误 [英] error in dropdown using asp.net

查看:48
本文介绍了使用asp.net的下拉菜单中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法绑定asp.net中的下拉列表,代码为

i am not able to bind the dropdown in asp.net the code is

HimaniComboBox module_cmb = (HimaniComboBox)tb_main_information.FindControl("drpparenttype");
HimaniComboBox module_field_cmb = (HimaniComboBox)tb_main_information.FindControl("drpchildid");
module_field_cmb.Items.Clear();
module_field_cmb.Items.Add(new HimaniComboBoxItem("--Select--","0"));
if (module_cmb.SelectedItem.Text != "--Select--")
{
  DataTable dt = comm.run_query("select Name,ID from " + module_cmb.SelectedValue + " Order By Name");
  module_field_cmb.DataSource = dt;
  module_field_cmb.DataTextField = "Name";
  module_field_cmb.DataValueField = "ID";
  module_field_cmb.DataBind();
  module_field_cmb.SelectedValue = comm.return_String("select Child_ID from Call where ID=''" + Session["CALL_ID"].ToString() + "''");
}


该代码附带错误:


the error is come with this code:

System.ArgumentOutOfRangeException: Selection out of range
Parameter name: value


希望您能解决.
请帮助我


I hope you can solve it.
Please help me

推荐答案

为什么不尝试调试代码?这将帮助您找到发生此错误的确切行.
然后您可以自己找出问题所在!
Why dont you try and debug your code? This will help you get to the exact line where this error occurs.
You can then yourself figure out what the problem could be!


comm.return_String("select Child_ID from Call where ID=''" + Session["CALL_ID"].ToString() + "''");返回的值不在module_field_cmb.DataSource

简单使用DEBUGGER可以告诉您错误在哪里以及原因.请尝试解决.

此外,使用查询获取数据的方式也不可行.阅读有关参数化查询的信息.
Looks like value returned by comm.return_String("select Child_ID from Call where ID=''" + Session["CALL_ID"].ToString() + "''"); is not in the module_field_cmb.DataSource

A simple use of DEBUGGER can tell you where the error is and why. Please try and handle it out.

Further, the way you are using the queries to get data is not suggestible. Read about parameterized queries.


请尝试以下操作

祝你好运


you try this please

good lucky


HimaniComboBox module_cmb = (HimaniComboBox)tb_main_information.FindControl("drpparenttype");
HimaniComboBox module_field_cmb = (HimaniComboBox)tb_main_information.FindControl("drpchildid");
module_field_cmb.Items.Clear();
module_field_cmb.Items.Add(new HimaniComboBoxItem("--Select--","0"));
if (module_cmb.SelectedItem.Text != "--Select--")
{
   string strQuery = select Name,ID from " + module_cmb.SelectedValue + " Order By Name";            
   SqlDataAdapter sqladapter = new SqlDataAdapter(strQuery , sqlconn);
   DataSet mydata = new DataSet();
   sqladapter.Fill(mydata, strQuery );
   module_field_cmb.DataSource = mydata;
   module_field_cmb.DataTextField = "Name";
   module_field_cmb.DataValueField = "ID";
   module_field_cmb.DataBind();
   module_field_cmb.SelectedValue = comm.return_String("select Child_ID from Call where ID=''" + Session["CALL_ID"].ToString() + "''");
}


这篇关于使用asp.net的下拉菜单中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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