datalist 事件的问题
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);
}
事件永远不会被触发!无论我按按钮链接多少次.. 为什么会这样:( ..
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>
And the 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">
The code behind event:
protected void DataList2_SelectedIndexChanged(object sender, EventArgs e)
{
Server.Transfer("AnswerQuestion.aspx?x=" + DataList2.DataKeyField + "&question=" + DataList2.SelectedValue + "&time=" + DateTime.Now);
}
The event never gets triggered!! no matter how many times I press the button link.. Why is that :( ..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试
Try
尝试指定 CommandName 进行选择。
或者,您可以使用 ButtonColumn
Try specifying CommandName for selection.
Alternatively, you could use a ButtonColumn