Click here to Skip to main content
15,888,286 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a datalist that populates records from database. In the datalist I have some labels and Linkbuttons that have set visibility to false. Now I want them to show on page load event based on some user defined functions that I have defined their stored procedure in the db. For instance I have a user defined function

void GetOnlinBooksForSale() Now when I call this function I would like to hide some labels while set the visibility of certain link button to true

What I have tried:

I tried this button am stcuk
void Visibility_ItemDataBound(object sender, DataListItemEventArgs e)
       {
           if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
           {
               LinkButton lnkbtnAddToCart = (LinkButton)e.Item.FindControl("lnkbtnAddToCart");
               LinkButton lnkkbtnRequest = (LinkButton)e.Item.FindControl("lnkkbtnRequest");
               Label lblNote = (Label)e.Item.FindControl("lblNote");
               Label lblRequested = (Label)e.Item.FindControl("blRequested");
               LinkButton lnkButtonRead = (LinkButton)e.Item.FindControl("lnkButtonRead");

           }


Here is my datalist
<asp:DataList ID="DataList1" runat="server" RepeatDirection="Horizontal" RepeatColumns="3">
                                   <HeaderStyle BackColor="Black" Font-Bold="true" Font-Size="Large" ForeColor="White" HorizontalAlign="Center" />
                                   <HeaderTemplate>ALL AVAILABLE BOOKS</HeaderTemplate>
                                   <ItemTemplate>
                                       <div style="width: 350px; text-align: left;font-size:small">
                                           "color: rgba(0, 0, 128, 1)" id="Book_nameLabel" width="100px" height="150px" class="row">  Add to Cart</asp:LinkButton>
                                               ^__b>
                                                   <asp:LinkButton ID="lnkButtonRead" Visible="false" CssClass="btn-outline-secondary" runat="server">Read (free)</asp:LinkButton>
                                               ^__b>
                                                   <asp:LinkButton ID="lnkkbtnRequest" Visible="false" CssClass="btn-outline-secondary" runat="server">On Request</asp:LinkButton>
                                               ^__b>
                                                   <asp:Label ID="lblRequested" Visible="false" Style="color: #7d7d7d" runat="server" Text="Requested"></asp:Label>
                                           </div>

                                       </div>
                                       </div>
                                   </ItemTemplate>
                               </asp:DataList>
Posted
Comments
Richard Deeming 19-Apr-22 12:46pm    
You've forgotten to explain precisely where you are stuck, or what the problem is.

Click the green "Improve question" link and update your question to include a clear description of what you are trying to do, what you have tried, and where you are stuck. Include the full details of any errors along with the relevant parts of your code.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900