I have a GridView and a select link in the GrdiView, when the item is selected I want it to read the contents to a textbox below the GridView. 我能想到的唯一方法是访问选择链接的 onClick 函数的背后代码。问题是我不确定如何做到这一点。
更新的果酱方法:
C# 代码
protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
{
GridView1.SelectedIndex = e.NewSelectedIndex;
TextBox1.Text = GridView1.Rows[e.NewSelectedIndex].Cells[0].Text;
}
正面代码
<asp:GridView ID="GridView1" OnSelectedIndexChanging="GridView1_SelectedIndexChanging" runat="server" AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333"
GridLines="None">
更新我的方法:
protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
{
int i = GridView1.SelectedIndex;
ds.Tables["Comments"].Rows[i]["Comment"] = TextBox1.Text;
}
也试过这个,但我得到一个错误-> System.IndexOutOfRangeException:位置-1没有行。
谢谢。