Home » Asp.net

Convert int value to string in gridview column?

Hello all. I have a column in my gridview titled Progress. The data is currently consisting of integer values such as 1, 2, and 3. How can I change them to say "Good", "Review", and "Redo" based on their value? 


4 Answers Found


Answer 1


                    <asp:Label ID="lblProgres" Text='<%#FormatInput(Eval("Progress") %>' runat="server" />

Code Behind:(C#)

    protected string FormatInput(object progress)
        string retValue = "";       
        string input = progress.ToString();
        if (input == "1")
            retValue = "Good";
        else if(input == "2")
            retValue = "Review";
            retValue = "Redo";

        return retValue;

Like Above. You could also do this in your Sql Stored Procedure


Answer 2

thanks! any chance you know how to do it in VB.net though? 


Answer 3

Try this, might be some syntax errors: ( i dont work in vb)

Protected Function FormatInput(progress As Object) As String
	Dim retValue As String = ""
	Dim input As String = progress.ToString()
	If input = "1" Then
		retValue = "Good"
	ElseIf input = "2" Then
		retValue = "Review"
		retValue = "Redo"
	End If

	Return retValue
End Function

I used:


to convert


Answer 4

nice! thats what I figured would work, thanks so much for the help! :D 



<< Previous      Next >>

Microsoft   |   Windows   |   Visual Studio   |   Sharepoint   |   Azure