修改selectCommand以后要重新bind()到gridview1去才生效
【 在 cluefly (心中的结) 的大作中提到: 】
: 标 题: 请教:asp.net 修改数据源的selectCommand
: 发信站: 水木社区 (Fri Oct 9 12:33:41 2009), 站内
:
: 偶是asp.net新手,请教:
: gridview1绑定一个sqldatasource,然后想通过texbox和button实现查询,将新的数据绑定到
: gridview1。查了下资料,好像说 修改数据源的selectCommand可以实现偶所需的功能。
: 偶试着写了下:
: protected void Button2_Click(object sender, EventArgs e)
: {
: string a = TextBox1.Text ;
: string b = DropDownList1.SelectedValue;
:
: if (a == "")
: {
: SqlDataSource1.SelectCommand = "SELECT 1,nameS.name AS 姓名, nameS.gonghao AS 工号, gangweiS.gangwei AS 岗位, banzuS.banzu_name AS 班组,nameSbaseMsg.addr AS 地址, nameSbaseMsg.tel AS 电话, nameSbaseMsg.Stel AS 短号,nameSbaseMsg.xueli AS 学历, nameSbaseMsg.zch AS 职称, nameSbaseMsg.dji AS 等级, nameSbaseMsg.shenfenzheng AS 身份证, nameSbaseMsg.brith AS 生日, nameSbaseMsg.sex AS 性别, nameSbaseMsg.mianmao AS 面貌 FROM nameSbaseMsg INNER JOIN nameS ON nameS.ID_name = nameSbaseMsg.ID_name INNER JOIN banzuS ON nameS.ID_banzu = banzuS.ID_banzu INNER JOIN gangweiS ON nameS.ID_gangwei = gangweiS.ID_gangwei";
: }
: else
: {
: switch (b)
: {
: case "姓名":
: {
: SqlDataSource1.SelectCommand = "SELECT 1,nameS.name AS 姓名, nameS.gonghao AS 工号, gangweiS.gangwei AS 岗位, banzuS.banzu_name AS 班组,nameSbaseMsg.addr AS 地址, nameSbaseMsg.tel AS 电话, nameSbaseMsg.Stel AS 短号,nameSbaseMsg.xueli AS 学历, nameSbaseMsg.zch AS 职称, nameSbaseMsg.dji AS 等级, nameSbaseMsg.shenfenzheng AS 身份证, nameSbaseMsg.brith AS 生日, nameSbaseMsg.sex AS 性别, nameSbaseMsg.mianmao AS 面貌 FROM nameSbaseMsg INNER JOIN nameS ON nameS.ID_name = nameSbaseMsg.ID_name INNER JOIN banzuS ON nameS.ID_banzu = banzuS.ID_banzu INNER JOIN gangweiS ON nameS.ID_gangwei = gangweiS.ID_gangwei where nameS.name like '%a%' order by nameS.name";
: }
: break;
: 。。。
:
: 其中a是texbox,b是dropdownlist
:
: 测试发现无法实现偶所需的功能
: --
: But I know that you've got your reasons
:
: these things that are pleasing you
:
: Can hurt you somehow
:
:
: ※ 修改:·cluefly 于 Oct 9 12:40:40 2009 修改本文·[FROM: 220.189.223.*]
: ※ 来源:·水木社区 newsmth.net·[FROM: 220.189.223.*]
--
修改:cluefly FROM 220.189.223.*
FROM 114.250.108.*