我是由数据库里一次性将一个表抽到DataSet然后再放到DataGridViiew里的,但这样会将所有SELECT出来的字段都在DataGridViiew控件里显示出来,我现在只想显示一部分字段,但在SQL SELECT里是要全部字段查出来的,因为我另有他用,但不想显示出来,请问如何操作?谢了!
解决方案 »
- 有關發短信問題
- Winsock 控件 怎么用????
- comboBox中数据绑定的问题
- stephenZL接分,答应了解决问题后600分
- .net高手请进(和iframe内框架相关问题)
- 通过Wireshark抓包生成的PCAP文件,如何使用C#对这些包联合Wireshark的过滤器进行解析?
- 哪位用 vs.net 2005 里的水晶报表成功的部署在 xp 系统上???????????讲解给小弟听下!!!
- 执行当前 Web 请求期间,出现未处理的异常,help~~~~
- 怎样弹出一个对话框!
- <Visual C#.NET深入编程>一书怎样?
- datagridview 显示指定列
- 关于datarow 事件操作
/// 在GridView上邦定数据
/// </summary>
/// <param name="delflag">false-正常绑定,不显示删除的数据
/// true-正常绑定,显示所有数据包括删除的数据</param>
private void Bind(string bh, string qssj,string kssj,string jssj, bool delflag)
{
string[] arrHeadName ={ "流水号", "车次编号", "车辆编号", "最大载客数", "是否加座", "加座数", "车主", "驾驶员", "发车时间", "检票口设置", "车次种类", "检票时间设置", "线路编号","是否可联网售票","可否预售","预售天数","开行方式","车次票价计划编号","票价是否调整","调整票价编号","车次报班卡编号","报班状态","运行状态","隶属公司编号","操作人","操作时间","是否为新增车次","车主名称","标志" };
// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
string[] arrFieldName ={ "流水号", "车次编号", "车辆编号", "最大载客数", "是否加座", "加座数", "车主", "驾驶员", "发车时间", "检票口设置", "车次种类", "检票时间设置", "运行线路编号", "是否可联网售票", "可否预售", "预售天数", "开行方式", "车次票价计划编号", "票价是否调整", "调整票价编号", "车次报班卡编号", "报班状态", "运行状态", "隶属公司编号", "操作人", "操作时间", "是否为新增车次", "车主名称", "标志" };
string[] arrColStyle ={ "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1","1" };
string[] arrFormat ={ null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null };
double[] arrWidth ={ 0, 10, 10, 0, 0, 0, 0, 0, 20, 0, 0, 0, 10, 0, 0, 0, 10, 0, 0, 0, 0, 10, 10, 0, 0, 0, 0,10, 0 };
string[] arrUrlFields ={ null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null };
bool[] arrVisible ={ false, true, true, false, false, false, false, false, true, false, false, false, true, false, false, false, true, false, false, false, false, true, true, false, false, false, false,true, false };
TDGridView1.AddCol(arrHeadName, arrFieldName, arrColStyle, arrFormat, arrWidth, arrUrlFields, arrVisible, dynPara.Lsccgl(bh, qssj,kssj,jssj, delflag));
}
AddCol方法如下:/// <summary>
/// binding GridView,auto create column and give
/// the head、value、format、width and so on
/// </summary>
/// <param name="HeadName">header name</param>
/// <param name="FieldNames">database field name</param>
/// <param name="ColStyle">column style:1-BoundField</param>
/// <param name="ColFormat">format</param>
/// <param name="ColWidth">width</param>
/// <param name="urlFields">url</param>
/// <param name="Visibles">visible</param>
/// <param name="dv">dataView</param>
/// <returns>return true if success
/// or return false when failture</returns>
public bool AddCol(string[] HeadName, string[] FieldNames, string[] ColStyle, string[] ColFormat, double[] ColWidth, string[] urlFields, bool[] Visibles,DataView dv)
{
try
{
#region old code
//this.Columns.Clear();
//this.AutoGenerateColumns = false;
//for (int i = 0; i < ColStyle.Length; i++)
//{
// switch (ColStyle[i])
// {
// case "1"://绑定列
// BoundField BdCol = new BoundField();
// BdCol.DataField = FieldNames[i];
// BdCol.HeaderText = HeadName[i];
// if (ColFormat[i] != null)
// {
// BdCol.DataFormatString = ColFormat[i];
// }
// BdCol.HeaderStyle.Width = Unit.Percentage(ColWidth[i]);
// if (Visibles[i] != true)
// {
// BdCol.Visible = false;
// }
// this.Columns.Add(BdCol);
// break;
// }
#endregion
this.Columns.Clear();
this.AutoGenerateColumns = false;
for (int i = 0; i < ColStyle.Length; i++)
{
switch (ColStyle[i])
{
case "1"://bound field
BoundField BdCol = new BoundField();
BdCol.DataField = FieldNames[i];
BdCol.HeaderText = HeadName[i];
if (ColFormat[i] != null)
{
BdCol.DataFormatString = ColFormat[i];
}
this.Columns.Add(BdCol);
break;
case "2"://checkbox field
CheckBoxField TpCol = new CheckBoxField ();
TpCol.DataField = FieldNames[i];
TpCol.HeaderText = HeadName[i];
//if (ColFormat[i] != null)
//{
// TpCol.DataFormatString = ColFormat[i];
//}
this.Columns.Add(TpCol);
break;
}
} if (dv.Table .Rows .Count == 0)
{
dv.Table.Rows.Add(dv.Table.NewRow());
}
//binding dataSource
this.DataSource = dv;
this.DataBind(); for (int i = 0; i < ColStyle.Length; i++)
{
switch (ColStyle[i])
{
case "1"://binding column
//visible setting
if (Visibles[i] != true)
{
this.Columns[i].Visible = false;
}
//width setting
this.Columns[i].HeaderStyle.Width = Unit.Percentage(ColWidth[i]);
break; }
}
return true;
}
catch
{
return false;
}
}