Click here to Skip to main content
15,905,614 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have an image which should be displayed only for premium members.. i have a database field named ispaid which differtiates free and premium customers. so how do i bind visible property..???plz help me . Image Id is Image3
XML
<asp:DataList ID="CandidateFProfileDataList" RepeatColumns="1" CellPadding="0" CellSpacing="0"
                                                        RepeatDirection="Vertical" runat="server" HorizontalAlign="Left" ItemStyle-VerticalAlign="Top"
                                                        DataKeyField="CandidateId"
                                                        OnItemDataBound="CandidateFProfile_ItemDataBound" Height="364px"
                                                        style="margin-right: 0px">
                                                        <ItemStyle VerticalAlign="Top"></ItemStyle>
                                                        <ItemTemplate>
                                                            <table width="260px" border="0" cellpadding="0" cellspacing="0">
                                                                <tr>
                                                                    <td colspan="4" style="height: 5px">
                                                                    </td>
                                                                </tr>
                                                                <tr>
                                                                    <td style="width: 70px" valign="top" align="center">
                                                                        <a id="hrefFProfile" runat="server">
                                                                            <asp:Image ID="Image1" Height="70px" Width="70px" ImageUrl='<%# isAvailF(PhotoImagesPath + Eval("PhotoPath")) %>'
                                                                                BorderColor="#0155A7" BorderStyle="Solid" BorderWidth="1px"
                                                                            runat="server" /></a>
                                                                    </td>
                                                                    <td style="width: 10px">
                                                                    </td>
                                                                    <td valign="top" style="width: 182px">
                                                                        <table cellpadding="0" cellspacing="0" border="0" width="182px">
                                                                            <tr class="featuredjianbrides">
                                                                                <td style="width: 80px">
                                                                                    Profile ID
                                                                                </td>
                                                                                <td style="width: 3px">
                                                                                    :
                                                                                </td>
                                                                                <td style="width: 105px">
                                                                                    <asp:Label ID="lblCanidtaeID1" runat="server" Text='<%#Eval("CandidateID")%>' Visible="False"></asp:Label>
                                                                                    <a id="hrefProfileDetails1" runat="server">
                                                                                        <asp:Label ID="lblFCandidateCode" runat="server"
                                                                                        Text='<%# "LP -" + Eval("CandidateID") %>'></asp:Label></a>
                                                                                </td>
                                                                                <td>
                                                                                    <asp:Image ID="Image3" runat="server" ImageUrl="App_Themes/Images/paid.png"
                                                                                        Visible="<%# ispaid() %>" /></td>
                                                                            </tr>
                                                                            <tr>
                                                                                <td colspan="3" class="smalltxt">
                                                                                    <asp:Label runat="server" ID="lblFAge" Text='<%#Eval("CandidateAge")%>' class="smalltxt"></asp:Label>Yrs,
                                                                                    <asp:Label runat="server" ID="lblFHeight" Text='<%#Eval("Height")%>' class="smalltxt"></asp:Label>
                                                                                    cms
                                                                                </td>
                                                                            </tr>
                                                                            <tr>
                                                                                <td class="profilematter" align="left">
                                                                                    Cast
                                                                                </td>
                                                                                <td>
                                                                                    :
                                                                                </td>
                                                                                <td colspan="3" align="left">
                                                                                    <asp:Label runat="server" class="profilematter" ID="lblFCast" Text='<%#Eval("ReligionCastName")%>'></asp:Label>
                                                                                </td>
                                                                            </tr>
                                                                            <tr>
                                                                                <td nowrap="nowrap" class="profilematter" align="left">
                                                                                    Mother Tongue
                                                                                </td>
                                                                                <td>
                                                                                    :
                                                                                </td>
                                                                                <td colspan="3" class="profilematter" align="left">
                                                                                    <asp:Label runat="server" ID="lblFMotherTongue" Text='<%#Eval("MotherTongue")%>'></asp:Label>
                                                                                </td>
                                                                            </tr>
                                                                            <tr>
                                                                                <td class="profilematter" align="left">
                                                                                    Location
                                                                                </td>
                                                                                <td>
                                                                                    :
                                                                                </td>
                                                                                <td colspan="3" class="profilematter" align="left">
                                                                                    <asp:Label runat="server" ID="lblFLocation" Text='<%#Eval("Location")%>'></asp:Label>
                                                                                </td>
                                                                               </tr>
                                                                        </table>
                                                                    </td>
                                                                    <td style="width: 5px">
                                                                    </td>
                                                                </tr>
                                                                <tr>
                                                                    <td colspan="4" style="height: 5px">
                                                                    </td>
                                                                </tr>
                                                            </table>
                                                        </ItemTemplate>
                                                    </asp:DataList>
Posted
Comments
Slacker007 18-Mar-11 6:25am    
Please reformat your code snippet so that it is neater and easier to read. Thanks.
Albin Abel 18-Mar-11 6:43am    
It is not good advice using business logic at the presentation. At least you can use code behind to set or not set the image to the image control. Better avoid <% %> insertions i.e late binding as much as possible. This is just for your information. Someone will post an answer as soon as possible
Member 7764639 27-Mar-11 23:03pm    
hey can u give me ur email address .. this is getting complicated.. plz lend some help to me
Albin Abel 27-Mar-11 23:15pm    
Hi I will look at this question today and will provide necessary answer. No worries
Albin Abel 28-Mar-11 0:46am    
I have answered your question. See if that helps

for example

if(premium){
yourDataTable.Rows[rowNumber][image]="<img src="yourImageUrl" style="display:inline" alt="" />";}
else{
yourDataTable.Rows[rowNumber][image]="<img src="yourImageUrl" style="display:none" alt="" />";}


In your DataList

<asp:datalist xmlns:asp="#unknown">
  <table>
    <tr>
        <td><%#DataBinder.Eval(Container.DataItem,"image") %></td>
    </tr>
  </table>
</asp:datalist>
 
Share this answer
 
Comments
Member 7764639 26-Mar-11 13:18pm    
thnxs for your solution .. but i dont have to take image from database .. it is in my project in folder named images...
raju melveetilpurayil 28-Mar-11 6:41am    
you can take image from db/folder its do not make any problem
Hi
Set the paid value to a field.

XML
<ItemTemplate>
    <asp:TextBox ID="IsPaid" runat="server"  Text='<%#Eval("IsPaid")%>' />
</ItemTemplate>


However this is a dirty way. You can get the datasource in code behind , convert to the corresponding object (may be dataset) and get the paid value using the candidate id would be fine. As I am not sure about your data source I am giving this alternate way.

Then in your Item DataBound event handler Check the isPaid and make the image hidden or not.

C#
protected void CandidateFProfile_ItemDataBound(object sender, DataListItemEventArgs e)
{
    //check the is Paid. If true make the image visible
    //if you have better way to check the paid value here that would be fine.
    TextBox isPaid = (TextBox)e.Item.FindControl("IsPaid");
    string paid = isPaid.Text;
    if (paid == "false" || paid == "0")
    {
        e.Item.FindControl("image3").Visible = false;
    }
    e.Item.FindControl("IsPaid").Visible=false;
}
 
Share this answer
 
v2
Comments
Albin Abel 28-Mar-11 0:51am    
Alternatively you can check the isPaid in late binding set style="visibility:hidden" on that image.
Check whether the stored procedure returns The value of IsPaid Column .. if yes then bind the visible property with Eval("IsPaid").
 
Share this answer
 

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