[Last Call] Learn how to a build a cloud-first strategyRegister Now


asp.net c# gridview

Posted on 2007-10-11
Medium Priority
Last Modified: 2013-11-26
i used gridview wizard to create data list and it works fine. However, I want to have make some condition when the gridview is looping. e.g.
when the gridview is running, I want to show if statusid = 1 then hyperlink = "accept" else statusid = 2 show something else...
how can I do that?

500 points for completed working code...

This is asp.net 2.0 c#
Question by:riskyricky1972
  • 3
LVL 16

Expert Comment

ID: 20061849
sorry, your request is not very clear

do you always want to display a hyperlink but vary the Link text dependant on one of the values from the data source?

or do you want to display a hyperlink if statusid=1 and then some other sort of control if satusid = 2?
LVL 16

Accepted Solution

McExp earned 1000 total points
ID: 20062107
Ok so I'm guessing at a solution

                <asp:HyperLink runat="server" ID="hlLink" NavigateUrl="~/Default.aspx" Text="Accept" Visible='<%# ((int)Eval("StatusId") == 1) %>' />
                <asp:Label runat="server" ID="lblOther" Text="Other" Visible='<%# ((int)Eval("StatusId") == 2) %>' />

The above code will show a hyperlink if StatusId = 1 and a "Other" Label if StatusId = 2

Assisted Solution

SU-30MKI earned 1000 total points
ID: 20064356
You can achieve this  in codebehind.
Handle this functionality in  OnRowDataBound Event of gridview.
take hyperlink control and one more control say label in template column in gridview.

protected void gvAltLoc_RowDataBound(object sender, GridViewRowEventArgs e)

if (e.Row.RowType == DataControlRowType.DataRow)
            if (statuscode == "1")
              // make label invisible
                  //make hyperlink invisible
LVL 16

Expert Comment

ID: 20218775
Both solutions might be valid, one works from declarative code the other from code behind. I think me and the other poster both guessed at solutions as we where unable to get a response from riskyricky1972

Expert Comment

ID: 20305253
Forced accept.

EE Admin

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month18 days, 6 hours left to enroll

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question