想在GridView查询出来的数据中单击一下任何一行就能选中此行.请教一下代码怎么写,该写在哪个地方

解决方案 »

  1.   

    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="ObjectDataSource1">
                    <Columns>
                        <asp:CommandField ShowSelectButton="True" />
                        <asp:BoundField DataField="CreateTime" HeaderText="CreateTime" SortExpression="CreateTime" />
                        <asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
                        <asp:BoundField DataField="CategoryId" HeaderText="CategoryId" SortExpression="CategoryId" />
                        <asp:CheckBoxField DataField="IsCommended" HeaderText="IsCommended" SortExpression="IsCommended" />
                        <asp:BoundField DataField="ArticleId" HeaderText="ArticleId" SortExpression="ArticleId" />
                        <asp:BoundField DataField="ChannelId" HeaderText="ChannelId" SortExpression="ChannelId" />
                    </Columns>
                </asp:GridView>
      

  2.   

    DataSourceID="ObjectDataSource1" 只的是什么id 可以详细说明下吗,还不行
      

  3.   

    DataView的实现方法应该跟DataGrid控件的实现方法相同的!下面是我用DataGrid实现的一个例子
    在页面的Load函数中绑定下面两个函数:
    BindDataToDataGrid();//邦定数据到DataGrid中,你也可在此函数中绑定数据到你的GridView中
    DataGridStateControl();//此方法主要就是实现你想要的功能(任意单击一行数据的任一地方就可以选中此行)
    private void DataGridStateControl()
        {
                    DataGridTableStyle ts = new DataGridTableStyle();
    DataGridNoActiveCellColumn aColumnTextColumn;
               //DataGridNoActiveCellColumn 是下面另外定义的一个类。
    ts.AlternatingBackColor = Color.LightGray;
    ts.MappingName = tempTable.TableName;
    ts.AllowSorting = true;//允许进行排序
    int numCols = tempTable.Columns.Count;
    for (int i = 0;i< numCols;i++) //从第二列开始,不显示第一列的“职员编号”
      {
         aColumnTextColumn = new DataGridNoActiveCellColumn();
         aColumnTextColumn.MappingName = tempTable.Columns[i].ColumnName;
         aColumnTextColumn.HeaderText = tempTable.Columns[i].ColumnName;
         aColumnTextColumn.NullText = "";
         aColumnTextColumn.Format = "D";
         ts.GridColumnStyles.Add(aColumnTextColumn);
       }
    this.dataGrid1.TableStyles.Add(ts);
     
         }
    using System;
    using System.ComponentModel;
    using System.Collections;
    using System.Diagnostics;
    using System.Drawing;
    using System.Windows.Forms;namespace CustomerInfo
    {
    internal class DataGridNoActiveCellColumn : System.Windows.Forms.DataGridTextBoxColumn
    {
    //重载DataGridTextBoxColumn类的Edit方法,以便使点击DataGrid中任一单元格都选中当前行
    protected override void Edit(CurrencyManager source, int rowNum, Rectangle bounds, bool readOnly, string instantText, bool cellIsVisible)
    {
    int SelectedRow = rowNum;
    this.DataGridTableStyle.DataGrid.Select(SelectedRow);
    }
    }
    }
      

  4.   

    http://www.cnblogs.com/Jinglecat/archive/2007/07/15/818394.html