如何在gridview中基于eval更改项目模板中的显示文本? [英] How to change display text in item template based on eval in gridview?

查看:55
本文介绍了如何在gridview中基于eval更改项目模板中的显示文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个GridView,并且有一列名为status的列.在此列中显示值时,我使用了itemtemplate.当前,它显示EVAL值的结果,但我想显示基于eval值的文本.

I have a GridView and there is a column named status. On displaying the value in this column i have used itemtemplate. Currently, it shows the result of value of EVAL but i want to show text based on the values of eval.

 <asp:GridView ID="GridView1" runat="server"/>
 <Columns>
    <asp:TemplateField HeaderText="Status">
       <ItemTemplate>
        <%# Eval("ICB_SUBS_STATUS")%>
       </ItemTemplate>
       <EditItemTemplate>
           <asp:DropDownList ID="DropDownList1"  runat="server" SelectedValue='<%# Eval("ICB_SUBS_STATUS")%>'>
           <asp:ListItem Value = '0'>Applet not installed.</asp:ListItem>
           <asp:ListItem Value = '1'>ICB Service not activated. Applet installed.</asp:ListItem>
           <asp:ListItem Value = '2'>Active ICB Subscriber. Applet installed.</asp:ListItem>
           <asp:ListItem Value = '3'>Subscriber deactivated ICB. Applet installed.</asp:ListItem>
           </asp:DropDownList>
       </EditItemTemplate>
    </asp:TemplateField>
 </Columns>
</asp:GridView>

与上述情况一样,在编辑模板上,基于值显示下拉列表文本.另外,我想在gridview的正常显示上显示文本.任何想法和建议将非常有帮助!抱歉,如果我的英语不好!

As in above case, on edit template the dropdownlist text is shown based on value. Also, i want to show text on normal display of gridview. Any idea and suggestion will be very helpful!! Sorry, if my english is poor!

推荐答案

在您的代码后面创建一个方法,将该方法转换为人类可读的字符串.

Create a method in your code behind that translates this value to a human readable string.

protected string Translate_ICB_SUBS_STATUS(int ICB_SUBS_STATUS)
{
    switch (ICB_SUBS_STATUS)
    {
        case 0:
             return "Applet not installed.";
        case 1:
             return "ICB Service not activated. Applet installed.";
        ...

    }
}

然后在绑定中,使用方法

Then in your binding, use the method

<ItemTemplate>
<%# this.Translate_ICB_SUBS_STATUS(Int32.Parse(Container.DataItem("ICB_SUBS_STATUS").ToString())) %>
</ItemTemplate>

这篇关于如何在gridview中基于eval更改项目模板中的显示文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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