0

Hey all i have this piece of code here:

<asp:TemplateField>
   <ItemTemplate>
       <asp:LinkButton CommandArgument='<%#Eval("id") & "|" & Eval("theName")%>' runat="server" Text='<%#Eval("status")%>' CommandName='<%#Eval("status")%>' ID="statusLink" />
   </ItemTemplate>
</asp:TemplateField>

And where it says "status" it would either be "REJECTED", "PENDING" or "APPROVED". The problem being is that how can i not have a link if it says APPROVED but have different links for the REJECTED and APPROVED?

I check the clicks this way currently:

Protected Sub grdView_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles grdView.RowCommand
    Dim command As String = e.CommandName.ToString
    Dim theName() As String = Split(e.CommandArgument.ToString, "|")
    Dim cid As String = theName(0)

    If cid.Length <= 0 Then Exit Sub

    Select Case command
        Case "PENDING"
            Response.Redirect("/account/Req.aspx?ID=" & cid & "&ACCEPT=yes&NAME=" & theName(1))
        Case "REJECTED"
            Response.Redirect("/account/Req.aspx?ID=" & cid & "&ACCEPT=no&NAME=" & theName(1))
    End Select
End Sub

So if one records was like this:

 Bob | Barker | Bob@priceisright.com | PENDING (Approve | Reject)

Then the user would have the choice to either Approve or reject that person by pressing either link.

If it was approved already then it should just look like this:

 Bob | Barker | Bob@priceisright.com | Approve!

...without being linked with anything.

Any help would be great!

UPDATE

Maybe a better alternative to this is to just create the asp linkbuttons dynamically. But how would u insert them into the correct spot on the page?

StealthRT
  • 10,108
  • 40
  • 183
  • 342
  • You kow that even VB.NET is case-sensitive when strings are compared? You say the status caan be _"Pending"_ but you're checking for _"PENDING"_. A typo? – Tim Schmelter Aug 24 '12 at 20:48

1 Answers1

1

Quick, very quick workaround - but it doens't take care of not showing the link as simple text when it's approved, is something like this:

<asp:TemplateField>
   <ItemTemplate>
       <asp:LinkButton 
     OnClientClick='<%#Eval("status")=="Approved"?"javascript:return false;":""%>'
    CommandArgument='<%#Eval("id") & "|" & Eval("theName")%>' runat="server" Text='<%#Eval("status")%>' CommandName='<%#Eval("status")%>' ID="statusLink" />
   </ItemTemplate>
</asp:TemplateField>

What that does is that disables the form submission when the status is approved by returning false from the Javascript function call. Otherwise, it posts backs to the server.

Update:

Here's the complete solution, making the "Approved" link buttons displaying text only; without posting back or hyperlink:

<asp:TemplateField>
   <ItemTemplate>
       <asp:LinkButton 
     name='<%#Eval("status") %>'
    CommandArgument='<%#Eval("id") & "|" & Eval("theName")%>' runat="server" Text='<%#Eval("status")%>' CommandName='<%#Eval("status")%>' ID="statusLink" />
   </ItemTemplate>
</asp:TemplateField>

Now, you can simply call a JS function on Window.load to remove all the hrefs from elements with name Approved

<script>
    window.onload = function () {    
        //get elements with name Approved
        var aprovedLinks = document.getElementsByName("Approved");
        for (var i = 0; i < aprovedLinks.length; i++) {
            //remove the hyperlink
            aprovedLinks[i].removeAttribute("href", 0);
        }
    };
</script>
Icarus
  • 63,293
  • 14
  • 100
  • 115
  • Thanks for the code, lcarus. However, if the text was **REJECTED** **(without a link)** and i needed to place **(Approve)** next to it **(with a link)** so that they can above them then how would i modify the code above to do that? – StealthRT Aug 27 '12 at 12:16
  • Update OP with another alternative way. – StealthRT Aug 27 '12 at 12:40