簡體   English   中英

選擇DataGridView的行?

[英]Selecting row of DataGridView?

如何獲得數據網格視圖的整行。 我不知道從哪里開始。 我已經嘗試過了,但是不知道在哪里放置它。

dataGrid.Rows[index].Selected = true;

我只是在尋找對我有幫助的代碼! 謝謝

看來您想執行以下操作:

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>

產生以下輸出:

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM