2012-05-30 116 views
0

我如何獲得數據網格視圖的整個行。我不知道從哪裏開始。我已經嘗試過,但不知道該把它放在哪裏。 :選擇DataGridView的行?

dataGrid.Rows[index].Selected = true; 

我只是在尋找能夠幫助我的代碼。由於

+1

在哪你想用它的上下文嗎?要讀取它的數據,刪除它? –

回答

1

看來你想要做這樣的事情:

protected void Page_Load(object sender, EventArgs e) 
{ 
    this.FillGrid(); 
} 
protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e) 
{ 
    this.GridView1.SelectedIndex = e.NewSelectedIndex; 
    this.FillGrid(); 
} 

private void FillGrid() 
{ 
    this.GridView1.DataSource = new[] { "Hello", "World" }; 
    this.GridView1.DataBind(); 
} 

而在aspx文件:

<asp:GridView ID="GridView1" runat="server" 
     onselectedindexchanging="GridView1_SelectedIndexChanging"> 
     <Columns> 
      <asp:CommandField ShowSelectButton="True" /> 
     </Columns> 
     <SelectedRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" /> 
    </asp:GridView> 

其中產生這樣的輸出:

enter image description here