数据事件的问题
本文关键字:问题 事件 数据 | 更新日期: 2023-09-27 18:01:52
The DataList:
<asp:DataList ID="DataList2" runat="server"
DataSourceID="AllQuestionsResponded"
GridLines="Horizontal" DataKeyField="ThreadsID"
onselectedindexchanged="DataList2_SelectedIndexChanged">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server">'<%# Eval("ThreadTitle") %>'</asp:LinkButton>
<br />
<br />
</ItemTemplate>
</asp:DataList>
和sql dataSource:
<asp:SqlDataSource ID="AllQuestionsResponded" runat="server"
ConnectionString="<%$ ConnectionStrings:CP_AllQuestionsAnswered %>" SelectCommand="SELECT ThreadTitle, ThreadsID
FROM Threads
WHERE ThreadsID IN (SELECT ThreadsID
FROM Comments
WHERE UsersID=@UserID)
" onselecting="AllQuestionAskedDataSource_Selecting">
事件背后的代码:
protected void DataList2_SelectedIndexChanged(object sender, EventArgs e)
{
Server.Transfer("AnswerQuestion.aspx?x=" + DataList2.DataKeyField + "&question=" + DataList2.SelectedValue + "&time=" + DateTime.Now);
}
事件永远不会被触发!!不管我按多少次按钮链接…这是为什么?
Try
<asp:LinkButton ID="LinkButton1" runat="server" command="Select" autopostback="True">
尝试指定CommandName进行选择。
<asp:LinkButton ID="LinkButton1" CommandName="Select" runat="server">'<%# Eval("ThreadTitle") %>'</asp:LinkButton>
或者,您可以使用ButtonColumn
<asp:BoundColumn ButtonType="LinkButton"
HeaderText="ColumnHeader"
DataField="LinkButton"
CommandName="Select" />