Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
asp.net GridView数据操作_Asp.net - Fatal编程技术网

asp.net GridView数据操作

asp.net GridView数据操作,asp.net,Asp.net,我有GridView,它显示如下数据 Name Type Description abc 1 test xyz 2 test mno 1 another test 名称类型说明 abc 1试验 xyz 2试验 mno 1另一项测试 此数据是从sqldatasource检索的 问题:我想显示类型名称而不是ID Eg(如果类型=1,则应显示“Truck”,如果类型=2,则应显示“Driver”),

我有GridView,它显示如下数据

Name Type Description abc 1 test xyz 2 test mno 1 another test 名称类型说明 abc 1试验 xyz 2试验 mno 1另一项测试 此数据是从sqldatasource检索的

问题:我想显示类型名称而不是ID Eg(如果类型=1,则应显示“Truck”,如果类型=2,则应显示“Driver”),我只有2种类型(Truck和Driver)

有人能帮我吗

谢谢,
S

您可以将“Type”列的当前
BoundField
替换为
TemplateField

我假设您没有将
GridView
AutoGenerateColumns
设置为true

        <asp:TemplateField>
            <HeaderTemplate>Type</HeaderTemplate>
            <ItemTemplate>
                <%# Convert.ToInt32(Eval("Type").ToString()) == 1 ? "Truck" : "Driver" %>
            </ItemTemplate>
        </asp:TemplateField>

类型

非常感谢。如果我想调用一个返回结果值的方法,这可能吗?