我用DataGrid绑定了一个表users,我想根据传过来的参数不同,比如默认显示users里的type,如传过来一个参数id=2,我就更改绑定项type为money,怎么实现
解决方案 »
- 画图的方法
- 一个非常烦人的问题。例如想用.Checked=true让程序选中选项钮,却在暗中自动激发了它的CheckedChanged事件。类似的问题,在一个有5万行以上的代码中如何去发现它呢?难道要经常一句一句
- 为什么我在datagridview改动的数据不会将改动保存到数据库
- 大家知道怎么实现qq那种头像循环吗? c/s模式的。好像用datagrid这种也不能那样做呀! c/s下面又没有摸版列
- 看过《Advanced .NET Remoting》的请进!(没看过我这里可以下载)
- c#除了使用microsoft pivottable做数据透视表还可以用其它控件吗?
- wpf listview 和 gridview 滚动条 显示 但是 不能滚动
- DataGrid的模板列的绑定
- 请教如何修改注册表?
- 求救!求救!求救!!!!HELP ME!!!!!!!!
- DataGridViewLinkColumn 绑定dataset 中的datatable,源码?
- 遍历映射盘的目录和文件并删除指定文件的问题
web:选择好数据源直接绑定好了。
定义一个变量condition
private string condition = "";
然后在pageload里写
string id = Request["id"];
switch (type)
{
case "2":
condition = "where type='money'"
break;
case "3":
condition = "where type=..."
break;
case "4":
condition = "where type=..."
break;
}
比如你的sql语句是
sql="select * from tb"
现在改成
sql="select * from tb "+condition这样就可以了其它地方都不用改动了!
users里包括type,money,username,password等项
如果id=1,我的datagrid里显示type,username,password
如id=2,我的datagrid里显示money,username,password
datagrid里面你拉四列type,money,username,password
type,money 为隐藏列
如果id = 1,则显示type列
如果id = 2,则显示money列
string id = Request["id"];
if (id ==1 )
{
DataGrid1.Columns[0].Visible = true; //type 列
DataGrid1.Columns[1].Visible = false;//money 列 }
else if(id == 2)
{
DataGrid1.Columns[0].Visible = false;
DataGrid1.Columns[1].Visible = true; }
如果是在web中可以在显示的时候下手
两个办法,一个是你在数据源上下手.令一个就是在显示的时候下手
有一个ItemDataBound事件e.Item.Cells[].Text可以修改你想要的东西
string strSql="";
switch (id)
{
case "1":
strSql="select type as Tmp,username,password from users';
break;
case "2":
strSql="select money as Tmp,username,password from users'; break;
}
绑定数据字段就是Tmp,username,password
Ok?