我有2个下拉列表pcode(项目代码)和fyyear(财政年度)我使用数据库编码填充然后在提交按钮我有一个gridview,它将显示与...相关的值 [英] i have 2 dropdownlist pcode(project code) and fyyear(financial year) which i am populating using database coding and then on submit button i have a gridview which will show me values related to...
问题描述
问题是我的''pcode''下拉列表工作得很好但是在我的''fyyear''下拉列表中它只显示我在gridview中的第一个条目的值,就好像一个项目是两年然后它显示我第一个日期范围的价值可以说是2010-2011之前,当我选择2011-2012时没有发生任何事情,它会自动显示第一次参赛的价值,即2010-2011 ??
这是我在提交按钮上使用的查询:
The problem is my ''pcode'' dropdownlist just works fine but in my ''fyyear'' dropdownlist its just showing me values for the first entry only in the gridview like if a project is of two years then its showing me value for first date range lets say for ex 2010-2011 and when i am selecting 2011-2012 nothing is happening and it is automatically showing me the values for first entry only that is 2010-2011??
this is the query i am using on my submit button :
protected void Button2_Click(object sender, EventArgs e)
{
try
{
SqlDataAdapter da = new SqlDataAdapter("select pcode,fyyear,date,salary,ta,contigency,nrc,institcharges,others from monthly where pcode=('" + DropDownList1.SelectedItem.Text + "' ) AND fyyear=('" + DropDownList2.SelectedItem.Text + "')",con);
DataTable dt = new DataTable();
da.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
}
catch (Exception ex)
{
ex.Message.ToString();
}
}
fyyear
和 pcode
是 varchar
示例pcode ICAR / 40/34,Dst-23/101
fyyear 2010-2011,2011-2012等
both fyyear
and pcode
are varchar
example pcode ICAR/40/34,Dst-23/101
fyyear 2010-2011, 2011-2012 and so on
推荐答案
尝试在下拉列表中将autopostback设置为true
Try setting autopostback to true in your dropdownlist
public void Button2_Click(object sender, EventArgs e)
{
try
{
SqlDataAdapter da = new SqlDataAdapter("select pcode,fyyear,date,salary,ta,contigency,nrc,institcharges,others from monthly where pcode=(''" + DropDownList1.SelectedItem.ToString() + "'' ) AND fyyear=(''" + DropDownList2.SelectedItem.ToString() + "'')", con);
DataTable dt = new DataTable();
da.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
DropDownList1.SelectedIndex = 0;
DropDownList2.SelectedIndex = 0;
}
catch (Exception ex)
{
ex.Message.ToString();
}
}
这篇关于我有2个下拉列表pcode(项目代码)和fyyear(财政年度)我使用数据库编码填充然后在提交按钮我有一个gridview,它将显示与...相关的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!