急!dropdownlist与gridview

magicapple4899 2009-04-12 11:04:31
dtopdownlist已绑定数据库,希望等够实现点击Button,gridview显示初相应信息,但是点击后什么都不显示 ,请高手帮忙
protected void Button3_Click(object sender, EventArgs e)
{
this.GridView1.DataSourceID = null;
DataTable dt = new DataTable();
String cmdText = "select * from Student where Scol='" + DropDownList4.Text + "'and Sdept='" + DropDownList5.Text + "'and Sclass='" + DropDownList3.Text + "'";
dt = Teacher.SelectRecords(cmdText);
this.GridView1.DataSource = dt;
this.GridView1.DataBind();
this.GridView1.Visible = true;
}
...全文
139 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
Riverwcj 2009-04-12
  • 打赏
  • 举报
回复
就像1楼所说的dt表还没有填充吧...
zftow110 2009-04-12
  • 打赏
  • 举报
回复
string cmdText ="";
if(DropDownList4.selectValue.ToString()="")
{
cmdText = "select * from Student where Scol='" + DropDownList4.selectValue.ToString() + "'and Sdept='" + DropDownList5.selectValue.ToString() + "'and Sclass='" + DropDownList3.selectValue.ToString() + "'";
}
else
{
.....
}
baoxuetianxia 2009-04-12
  • 打赏
  • 举报
回复
好像没有填充dt表吧
sqldataadapter 填充dt表 试试
magicapple4899 2009-04-12
  • 打赏
  • 举报
回复
具体怎样做,我没有写代码是直接用控件进行绑定的,
<asp:DropDownList ID="DropDownList4" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource4" DataTextField="colName" DataValueField="classId">
</asp:DropDownList> </td>
<td style="width: 68px; height: 26px;">
专业: </td>
<td style="width: 38px; height: 26px">
<asp:DropDownList ID="DropDownList5" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource3" DataTextField="deptName" DataValueField="classId">
</asp:DropDownList> </td>
这样就可以连起来,我设了个Button来进行搜索相应数据,但是搜索不出来。
agpsy 2009-04-12
  • 打赏
  • 举报
回复
联动可以用用第三方控件。
wappibz 2009-04-12
  • 打赏
  • 举报
回复
帮顶!
magicapple4899 2009-04-12
  • 打赏
  • 举报
回复
设过了
辰爸 2009-04-12
  • 打赏
  • 举报
回复
呵呵,楼主很有可能没有设置dropdownlist的是否回发属性,当然就不会有东西在gridview里显示了!!!
wuyq11 2009-04-12
  • 打赏
  • 举报
回复
删除 this.GridView1.DataSourceID = null;
字段绑定是否正确
magicapple4899 2009-04-12
  • 打赏
  • 举报
回复
这个我知道了。已经解决DropDownList4.selectValue.ToString() 就可以,只是现在还想做联动,如4楼所写,不知道怎样处理
itliyi 2009-04-12
  • 打赏
  • 举报
回复
DropDownList4.SelectedItem.Text
条件 不是Text
magicapple4899 2009-04-12
  • 打赏
  • 举报
回复
填充过了,dt = Teacher.SelectRecords(cmdText); 写在Teacher类里了
magicapple4899 2009-04-12
  • 打赏
  • 举报
回复
十分感谢,明白了,如果我还想做两级联动
<asp:DropDownList ID="DropDownList4" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource4" DataTextField="colName" DataValueField="classId">
</asp:DropDownList></td>
<td style="width: 68px; height: 26px;">
专业:</td>
<td style="width: 38px; height: 26px">
<asp:DropDownList ID="DropDownList5" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource3" DataTextField="deptName" DataValueField="classId">
</asp:DropDownList></td>
用DropDownList4.selectValue.ToString() 就不起作用了该怎么办?

62,267

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧