[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 392
  • Last Modified:

asp.net c# gridview

I used GridView Wizard and done some template edit. Everything is working fine. However,
I want to add if statement like if Eval("lastname") = "Chan" show something... Is it possible inside of gridview control in the souce code?
Please show me the codes with asp.net 2.0 c#  and 500pts is saving for you

 <asp:TemplateField SortExpression="firstname" HeaderText="Processed By">
                <ItemStyle  HorizontalAlign="Center" />
                <ItemTemplate>
                    <%#Eval("firstname")%>&nbsp;<%#Eval("lastname")%>
                </ItemTemplate>
            </asp:TemplateField>
           
0
riskyricky1972
Asked:
riskyricky1972
1 Solution
 
surajgupthaCommented:
Can you explain a little more on what you intend to do by embedding eval in itemtemplate?
0
 
cmhuntyCommented:
Create a public function in your code which has the condition and returns the require value:

    Public Function ProcessColumn(ByVal strLastName As String) As String
        Dim strOut As String
        If condition Then
            do this
        Else
            do this
        End If
        Return strOut
    End Function

Then in the template column you can call the function
<asp:TemplateField SortExpression="firstname" HeaderText="Processed By">
                <ItemStyle  HorizontalAlign="Center" />
                <ItemTemplate>
                    <%# ProcessColumn(Eval("lastname"))%>
                </ItemTemplate>
            </asp:TemplateField>

0
 
McExpCommented:
Include the code below in your ItemTempate

<asp:Label runat="server" ID="lbltest" Visible='<%# Eval("lastname").ToString()=="Chan" %>'>Whatever you want to display</asp:Label>

It will display the label contents if the criteria you set matches.

You can replace the Label control with most others as almost all asp controls have a visible property
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
riskyricky1972Author Commented:
cmhunty: this is asp.net c#
0
 
riskyricky1972Author Commented:
and i need completed codes. it is 500pts questions
0
 
McExpCommented:
but I've given you complete code?

What do you want to display conditionally?
0
 
McExpCommented:
Better?

<asp:TemplateField SortExpression="firstname" HeaderText="Processed By">
                <ItemStyle  HorizontalAlign="Center" />
                <ItemTemplate>
                    <%#Eval("firstname")%>&nbsp;<%#Eval("lastname")%>
<asp:Label runat="server" ID="lbltest" Visible='<%# Eval("lastname").ToString()=="Chan" %>'>Whatever you want to display</asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
0
 
riskyricky1972Author Commented:
MxExp: no...I want to show as hyperlink not label
0
 
McExpCommented:
ok, that's easy enough: -

<asp:HyperLink runat="server" ID="lbltest" NavigateUrl="SomePage.aspx" Visible='<%# Eval("lastname").ToString()=="Chan" %>'><%#Eval("firstname")%>&nbsp;<%#Eval("lastname")%></asp:HyperLink>
0
 
riskyricky1972Author Commented:
is visible supposed to be true or false?
0
 
riskyricky1972Author Commented:
McExp 500 pts for you since you are working with me...but I believe you do not solve my problem.
Please view this one...it may give you clear explaination.

http://www.experts-exchange.com/?qid=22888492
0
 
McExpCommented:
That hyperlink will be visible if the lastname is "chan"
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now