我用dropdownlist控件做了数据绑定,但却显示不出结果来
我用一个dropdownlist 控件做选择,另一个相应做出显示,但却显示不出效果来。各位高手帮忙找找原因。
public void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e)
{
string strvalue="";
for (int inti=0; inti< DropDownList1.Items.Count-1;inti++)
{
if(DropDownList1.Items[inti].Selected)
{
strvalue=DropDownList1.Items[inti].Value;}
}
int intvalue=int.Parse(strvalue);
string connectstring= "user id=sa;password=;initial catalog=vinegar;data source=thumb;Connect Timeout=30 ";
SqlConnection sqlConnection1=new SqlConnection(connectstring);
sqlConnection1.Open();
SqlDataAdapter sqlCommand1= new SqlDataAdapter("checkoption",sqlConnection1);
sqlCommand1.SelectCommand.CommandType=CommandType.StoredProcedure;
sqlCommand1.SelectCommand.Parameters.Add("@value", intvalue);
DataSet dataSet1=new DataSet();
sqlCommand1.Fill(dataSet1,"NocheckList");
sqlConnection1.Close();
DropDownList2.DataSource=dataSet1.Tables["NocheckList"].DefaultView ;
DropDownList2.DataBind();
}
附存储过程:
CREATE procedure dbo.checkoption
@value int
AS
if @value=0(
select AccesoryID from NoCheckList )
if @value=1(
select AccesoryName from NoCheckList)
if @value=2(
select Batch from NoCheckList)
if @value=3(
select vendor from NoCheckList)
if @value=4(
select ArrivalDate from NoCheckList)
if @value=5(
select TimeLimits from NoCheckList)
GO
public void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e)
{
string strvalue="";
for (int inti=0; inti< DropDownList1.Items.Count-1;inti++)
{
if(DropDownList1.Items[inti].Selected)
{
strvalue=DropDownList1.Items[inti].Value;}
}
int intvalue=int.Parse(strvalue);
string connectstring= "user id=sa;password=;initial catalog=vinegar;data source=thumb;Connect Timeout=30 ";
SqlConnection sqlConnection1=new SqlConnection(connectstring);
sqlConnection1.Open();
SqlDataAdapter sqlCommand1= new SqlDataAdapter("checkoption",sqlConnection1);
sqlCommand1.SelectCommand.CommandType=CommandType.StoredProcedure;
sqlCommand1.SelectCommand.Parameters.Add("@value", intvalue);
DataSet dataSet1=new DataSet();
sqlCommand1.Fill(dataSet1,"NocheckList");
sqlConnection1.Close();
DropDownList2.DataSource=dataSet1.Tables["NocheckList"].DefaultView ;
DropDownList2.DataBind();
}
附存储过程:
CREATE procedure dbo.checkoption
@value int
AS
if @value=0(
select AccesoryID from NoCheckList )
if @value=1(
select AccesoryName from NoCheckList)
if @value=2(
select Batch from NoCheckList)
if @value=3(
select vendor from NoCheckList)
if @value=4(
select ArrivalDate from NoCheckList)
if @value=5(
select TimeLimits from NoCheckList)
GO
...全文
相关推荐
ASP.NET中DropDownList下拉框列表控件绑定数据的4种方法
本文主要介绍了DropDownList控件4种绑定数据的基础用法,希望对大家能有所帮助。
ASP.NET MVC DropDownList数据绑定及使用详解
DropDownList 控件用于创建下拉列表。DropDownList 控件中的每个可选项都是由 ListItem 元素定义的!该控件支持数据绑定
asp.net Dropdownlist结合CheckBoxList多选下拉框
asp.net Dropdownlist结合CheckBoxList多选下拉框
解决dropdownlist数据绑定后选择下拉列表后返回的值不变或为空以及不执行SelectedIndexChanged事件
很多时候会出现这样的情况: 1、选择下拉列表中的某一项之后,string selectedid=Fanwei.SelectedValue;的值总是第一项的值,不管选哪项都是第一个值。 2、当选择一项之后无法执行SelectedIndexChanged事件。 其实很可能只是一个简单的问题,大家照着修改下试试,希望能帮到一点点小忙,这也是我之前遇到的问题。
DropDownList的数据绑定
DropDownList的数据绑定名称的直接方式


