简体   繁体   English

数据列表更多详细信息选项的问题

[英]issue with datalist more details option

I've created a datalist of jobs in my project.我在我的项目中创建了一个工作数据列表。 I'm trying to display just a few details with an option of show more information button.我正在尝试使用显示更多信息按钮选项来显示一些详细信息。 I've tried to do so but no matter which datalist block the user clicks on it always opens information on the first block.(instead of opening in the same block he clicked) Before clicking After clicking我试过这样做,但无论用户点击哪个数据列表块,它总是会打开第一个块的信息。(而不是在他点击的同一个块中打开)点击之前点击之后

aspx aspx

         <asp:DataList ID="DataList1" runat="server">
        <ItemTemplate>
           <div class="jobContainer">
              <div class="jobDetails">
                 <span class="jobName"><%# Eval("jobName") %></span><br /> 
                 <hr class="style13">
                 <a class="Details">    <b>Requirments: </b><span ><%# Eval("jobRequirments") %> WPM</span>   </a> 
                 <a class="Details">  <b>Salary: </b><span ><%# Eval("jobSalary")%> Shekel per hour</span>  </a>
                 <a class="Details">   <b>City: </b><span ><%# Eval("jobCity")%></span> <br />  </a>
                 <button id="moreDetailsButton" class="moreDetails" onclick="showDetails()" type="button">More Details</button>
                 <div id="secondDetails">
                    <a class="Details">           <b>Address: </b><span ><%# Eval("jobAddress")%></span>  </a>
                    <a class="Details">          <b>Description: </b><span ><%# Eval("jobDescription")%></span> <br />  </a>
                    <a class="Details">       <b>Contact: </b><span ><%# Eval("jobContact")%></span>  </a>
                    <a class="Details">         <b>Type: </b><span ><%# Eval("jobType")%></span> <br />  </a>
                    <asp:Button ID="Button1" class="moreDetails" runat="server" OnClick="Button1_Click" Text="Send nomination"/>
                 </div>
              </div>
           </div>
        </ItemTemplate>
     </asp:DataList>
     <script src="js/jobs.js" type="text/javascript"></script>

js js

function showDetails() {
document.getElementById("moreDetailsButton").style.display = "none";
document.getElementById("secondDetails").style.display = "block";

}

css css

.jobDetails {

margin-right: 4vw;
font-size: 20px;
margin-bottom: 1.25vh;

}

.jobName {
    font-size: 35px;
    font-weight: bold;
    margin-bottom: 3vh;
}

.jobContainer {
    border: solid 4px #c7aa8b;
    margin-left: 30px;
    padding: 3vh;
    margin-top: 2vh;

}


hr.style13 {
    height: 8px;
    border: 0;
    box-shadow: 0 15px 15px -17px #97611D inset;
    margin-bottom: 2vh;
}

.moreDetails {
    width: 190px;
    background: #c7aa8b;
    font-weight: bold;
    font-size: 20px;
    color: white;
    border: 0 none;
    border-radius: 2px;
    cursor: pointer;
    padding: 15px 5px;
    transition: none;
}

    .moreDetails:hover {
        box-shadow: 0 0 0 2px white, 0 0 0 3px #c7aa8b !important;
        transition: none;
    }

#secondDetails{
    display: none;
}
.Details{
    margin-left: 25px;
}
#moreDetailsButton {
    position: relative;
    margin-top: 3vh;
    margin-left: 40vw;
}

Your DataList ends up with multiple moreDetailsButton so id would not be using as selector.您的DataList以多个moreDetailsButton结束,因此id不会用作选择器。 So what you can do is give unique value to id and use that as selector.所以你可以做的是给id赋予唯一的价值并将其用作选择器。

Let's say JobName is unique for each row then you can create id by adding JobName to make them unique as following:假设JobName对于每一行都是唯一的,那么您可以通过添加JobName来创建id以使其唯一,如下所示:

<button id='<%# "moreDetailsButton_" + EVAL("JobName") %>' class="moreDetails" onclick='<%# "showDetails(" +Eval("JobName") + " );" %>' type="button">More Details</button>
<div id='<%# "secondDetails_" + EVAL("JobName") %>'>
//..

Your script will be:您的脚本将是:

function showDetails(jobName) {
    document.getElementById("moreDetailsButton_" + jobName).style.display = "none";
    document.getElementById("secondDetails_" + jobName).style.display = "block";
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM