0

I have GridView which displays data like this

Name      Type     Description

abc       1         test
xyz       2         test
mno       1         another test

This Data is retreived from sqldatasource.

Question: I want to display type Name instead of ID Eg( if type =1 then it should display "Truck" and if Type = 2 it should display "Driver") I have only 2 types(Truck and Driver)

Can anyone please help me in this?

Thanks, S

1 Answer 1

1

You can replace the current BoundField you have for the "Type" column to a TemplateField.

I'm assuming you are not setting the GridView AutoGenerateColumns to true.

        <asp:TemplateField>
            <HeaderTemplate>Type</HeaderTemplate>
            <ItemTemplate>
                <%# Convert.ToInt32(Eval("Type").ToString()) == 1 ? "Truck" : "Driver" %>
            </ItemTemplate>
        </asp:TemplateField>
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much. And would that be possible, If I want to call a method, which will be returning the result value?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.