Gridview SelectedIndex值集

时间:2010-01-21 17:54:29

标签: asp.net

使用Asp.Net C#。

<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" DataKeyNames="CategoryID"
                                DataSourceID="SqlDataSource1" OnSelectedIndexChanged="GridView2_SelectedIndexChanged" OnRowCommand="GridView2_RowCommand">
                                <Columns>
                                    <asp:CommandField ShowSelectButton="True" />
                                    <asp:BoundField DataField="CategoryID" HeaderText="CategoryID" InsertVisible="False"
                                        ReadOnly="True" SortExpression="CategoryID" />
                                    <asp:BoundField DataField="CategoryName" HeaderText="CategoryName" SortExpression="CategoryName" />
                                    <asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />
                                </Columns>
                            </asp:GridView>

protected void GridView2_SelectedIndexChanged(object sender,EventArgs e)     {

   GridView2.FindControl("CategoryID").Text=2;

}

希望在ridView2_SelectedIndexChanged方法中选择列值更改。怎么办?

1 个答案:

答案 0 :(得分:1)

您可以GridView2.SelectedRow.Cells[1].Text

访问所选的行单元格内容