在指定了datasource后用bind()方法。

解决方案 »

  1.   

    我用了,还不行:<,还是不能选定,在WinForm下可以
      

  2.   

    DataGird1.DataSource = someTable ;
    DataGrid1.DataBind();//关键这一句。
      

  3.   

    It is not that simple to slove in few lines of code. Pls refer to the following, I quote from somewhere(http://www.gotdotnet.com/community/messageboard/Thread.aspx?id=45783&Page=1#45783). I wish it helps."What I have done in this case is that I have created one select column,  made it the index 0 column. I have set the visibility of that column as false. And then attached the PostBack method of that column to every cell in the grid so that whenever user clicks anywhere in the grid it does the post back and also calles the select event. So that u get the SelectedIndexChanged event. Do following: 1. Create one select column in the datagrid and let it be at index=0, set the visibility=false. 
    2. Attach one method called "GenerateClientScript" to the OnItemDataBound of the datagrid. 
    eg. 
    <asp:datagrid id="dgPendingOpty" runat="server" CellPadding="4" CssClass="BaseGrid" AutoGenerateColumns="False" OnItemDataBound="GenerateClientScript"> 3. The code for GenerateClientScript:         protected void GenerateClientScript(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) 
            { 
                ListItemType itemType = e.Item.ItemType; 
                if ((itemType == ListItemType.Pager) || 
                    (itemType == ListItemType.Header) || 
                    (itemType == ListItemType.Footer)) 
                { 
                    return; 
                }             LinkButton button = (LinkButton)e.Item.Cells[0].Controls[0]; 
                e.Item.Attributes["onclick"] = Page.GetPostBackClientHyperlink(button, ""); 
                TableRow r=(TableRow)e.Item; 
                r.ToolTip="Click to select the row"; 
                TableCell c=(TableCell) e.Item.Cells[1]; 
                c.ToolTip="Click to get details"; 
                //e.Item.Attributes.Add("OnMouseOver", "this.style.cursor='hand';this.className='altRow';"); 
                //e.Item.Attributes.Add("OnMouseOut", "this.className='linkRow';"); 
            } 
    "
      

  4.   

    借宝地一用:
    http://expert.csdn.net/Expert/topic/1649/1649091.xml?temp=.7822992