datalist 事件的问题

发布于 2024-11-19 23:38:00 字数 1356 浏览 1 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

—━☆沉默づ 2024-11-26 23:38:01

尝试

<asp:LinkButton ID="LinkButton1" runat="server" command="Select" autopostback="True">

Try

<asp:LinkButton ID="LinkButton1" runat="server" command="Select" autopostback="True">
樱娆 2024-11-26 23:38:01

尝试指定 CommandName 进行选择。

<asp:LinkButton ID="LinkButton1" CommandName="Select" runat="server">'<%# Eval("ThreadTitle") %>'</asp:LinkButton>

或者,您可以使用 ButtonColumn

<asp:BoundColumn    ButtonType="LinkButton"
                    HeaderText="ColumnHeader" 
                    DataField="LinkButton"
                    CommandName="Select" />

Try specifying CommandName for selection.

<asp:LinkButton ID="LinkButton1" CommandName="Select" runat="server">'<%# Eval("ThreadTitle") %>'</asp:LinkButton>

Alternatively, you could use a ButtonColumn

<asp:BoundColumn    ButtonType="LinkButton"
                    HeaderText="ColumnHeader" 
                    DataField="LinkButton"
                    CommandName="Select" />
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文