【发布时间】:2014-09-17 18:58:38
【问题描述】:
这里我有一个GridView,它显示了书籍的详细信息:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" AllowPaging="true" BackColor="White"
BorderColor="#CCCCCC" BorderWidth="2px" CellPadding="2" CellSpacing="5" ForeColor="#000066"
GridLines="None" OnSelectedIndexChanged="GridView1_SelectedIndexChanged">
<RowStyle BackColor="#F7F7F7" />
<AlternatingRowStyle BackColor="#E7E7FF" />
<FooterStyle BackColor="White" />
<HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="White" ForeColor="#000066"
HorizontalAlign="Center" />
<SortedAscendingCellStyle BackColor="#F1F1F1" />
<SortedAscendingHeaderStyle BackColor="#007DBB" />
<SortedDescendingCellStyle BackColor="#CAC9C9" />
<SortedDescendingHeaderStyle BackColor="#00547E" />
<Columns>
<asp:CommandField ShowSelectButton="true" ControlStyle-ForeColor="Red" SelectText="Select" HeaderText="Select" />
<asp:TemplateField HeaderText="Id">
<ItemTemplate>
<asp:Label ID="LabelId" runat="server" Text='<%# Bind("Id") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Title">
<ItemTemplate>
<asp:Label ID="LabelTitle" runat="server" Text='<%# Bind("Title") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
现在,如果我想编辑书籍详细信息,还有文本框,所以当我单击 Select (ShowSelectButton="true") 时,列值应填充到文本框中。
我在GridView1_SelectedIndexChanged 事件中尝试过这样的操作,但是当我点击选择时没有任何反应:
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
textBoxID.Text = GridView1.SelectedRow.Cells[0].Text;
textBoxTitle.Text = GridView1.SelectedRow.Cells[1].Text;
}
【问题讨论】:
-
事件会触发吗?
-
是的,当我点击
Select时页面会重新加载。 -
我认为您希望标签数据在使用单击选择时应显示在相应的文本框中
-
你的 textBoxID 和 textBoxTitle 在哪里