在数据列表中绑定图像可见属性 [英] Binding image visible property in datalist

查看:55
本文介绍了在数据列表中绑定图像可见属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个只应为高级会员显示的图像.我有一个名为ispaid的数据库字段,该字段区分免费和高级客户.所以我该如何绑定可见属性.. ??? plz可以帮助我.图片ID为 Image3

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

<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>

推荐答案

例如

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>



将支付的值设置为一个字段.

Hi
Set the paid value to a field.

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



但是,这是一种肮脏的方式.您可以在后面的代码中获取数据源,将其转换为相应的对象(可能是数据集),然后使用候选ID来获得支付的值就可以了.由于我不确定您的数据源,因此我提供了另一种方法.

然后在Item DataBound事件处理程序中,检查isPaid并隐藏图像.



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.

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;
}


检查存储过程是否返回IsPaid Column ..的值,如果是,则将可见属性与Eval("IsPaid")绑定.
Check whether the stored procedure returns The value of IsPaid Column .. if yes then bind the visible property with Eval("IsPaid").


这篇关于在数据列表中绑定图像可见属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆