DataGridView的单元格默认是TextBox,那么我如何将某列的样式设置为DataGridViewLinColumn呢?我是用DataTable绑定DataGridView来显示数据库数据的,目前有一列值取得是false,那么我就给它一个超链接,让它能够接受单击事件,否则则不显示超链接,请问这应该怎么写?

解决方案 »

  1.   

    设置属性Visible = '<%# DataBinder.Eval(Container.DataItem, "你的相应的字段") %>'
      

  2.   

    您能说的具体点吗?我的程序不是.NET是Winform
      

  3.   

    我的问题不是在是否现实某个是不是超链接,而是整个列怎么让它先显示为超链接
    public static DataTable GetDataTable()
    {
    DataTable dataTable = new DataTable();
                dataTable.Locale = CultureInfo.InvariantCulture;
                dataTable.Columns.Add("Column1", typeof(string));
                dataTable.Columns.Add("Column2", typeof(string));
                dataTable.Columns.Add("Column3", typeof(string));            if (tempDataSet != null && tempDataSet.Tables[0].Rows.Count > 0)
                {
                    for (int i = rows; i < rows + length; i++)
                    {
                        DataRow row = tempDataSet.Tables[0].Rows[i];
                        DataRow TableRow = dataTable.NewRow();
                        TableRow["Column1"] = Convert.ToDateTime(row["StartTime"]).ToString();
                        TableRow["Column2"] = row["SubjectName"].ToString();
                        TableRow["Column3"] = row["StudentName"].ToString();//这个列的文本显示为超链接                    dataTable.Rows.Add(TableRow);
                    }                return dataTable;
                }     return null;
    }///在Panel上的DataGridView上显示数据库数据
    private void DisplayDataGridView()
    {
    DataTable dataTable = GetDataTable();
    if (dataTable != null && dataTable.Rows.Count > 0)
                {
                    this.dataGridView1.Columns[0].DataPropertyName = "Column1";
                    this.dataGridView1.Columns[1].DataPropertyName = "Column2";               ///如何让这个列的样式变为超链接DataGridViewLinkColumn
                    this.dataGridView1.Columns[2].DataPropertyName = "Column3";                this.bindingSource.DataSource = dataTable;
                    this.bindingNavigator.BindingSource = bindingSource;
                    this.dataGridView1.DataSource = bindingSource;
                }
    }