how to create a string from a value in datagrid

I have a value in a field that is either 1 or 2.  If it's 2, I want to add the word 'Test' to my URL, e.g.

'questiontest.aspx?questionid=2'

if it's 1 I want to go to

'question.aspx?questionid=1'

Here's my code currently:


 <asp:TemplateField HeaderText="Question" ItemStyle-Width="100px">
            <ItemTemplate>
                <asp:HyperLink ID="LinkQuestion" runat="server" Text='<%# string.Format("Question {0}", Eval("SortOrder")) %>'
                    NavigateUrl='<%# string.Format("~/Question{2}?question={0}&sort={1}", Eval("QuestionID"), Eval("SortOrder"), ??? %>' />
            </ItemTemplate>
        </asp:TemplateField>

How can I set the parameter {2} to be 'test' if the question field is 2?
d2foxAsked:
Who is Participating?
 
käµfm³d 👽Commented:
How about this:

...
NavigateUrl='<%# string.Format("~/Question{2}?question={0}&sort={1}", Eval("QuestionID"), Eval("SortOrder"), Convert.ToInt32(Eval("QuestionID")) == 2 ? "test" : string.Empty) %>' />

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.