我的数据列表中有以下itemTemplate

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

            </ItemTemplate>


这是我的dataList标记:

   <asp:DataList ID="DataList1" runat="server"
            DataSourceID="AllQuestionAskedDataSource"
            GridLines="Horizontal" DataKeyField="ThreadsID" >


这是sqldatasource:

<asp:SqlDataSource ID="AllQuestionAskedDataSource" runat="server"
    ConnectionString="<%$ ConnectionStrings:CP_AllQuestionsAnswered %>" SelectCommand="SELECT ThreadTitle, ThreadsID
    FROM Threads
WHERE UsersID=@UserID" onselecting="AllQuestionAskedDataSource_Selecting">


我正在尝试使用以下事件处理程序之一:

protected void DataList2_SelectedIndexChanged(object sender, EventArgs e)
{

}
protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
{

}


我想在这些事件处理程序之一中获得与所选行关联的ThreadID(通过单击数据列表中的行),然后从所选的特定行中获取ThreadTitle参数。

我该如何完成这项任务?

我基本上想检索我输入到sqldatasource中的sql参数,该参数与单击的特定行有关!!

我自己解决了这个问题:

    protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
{
    LinkButton link = (LinkButton)e.Item.FindControl("LinkButton1");
    string threadTitle = link.Text;

    string recordID = (DataList1.DataKeys[e.Item.ItemIndex]).ToString();
    string special = "";
}
enter code here

最佳答案

你可以做..

protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
{
    // Will give you current data key value
    Int32 threadID = Convert.ToInt32(e.CommandArgument);
    // if you want value of your control
    (ControlTypd)e.Item.FindControl("ControldId")
}

关于c# - 获取数据列表行详细信息,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6680262/

10-09 03:48