CommandItem Hyperlink NavigateUrl SelectedGridItem

2 posts, 0 answers
  1. kellyroberts
    kellyroberts avatar
    45 posts
    Member since:
    Jul 2007

    Posted 25 May 2010 Link to this post

    I have tried several ways to do this and none give the effect that I want.

    I have a grid with a custom commanditem template.  It has standard buttons for edit actions on selected grid item.

                            <div style="padding: 0 5px;margin:5px 5px 5px 5px;">  
                                <asp:HyperLink runat="server" ID="lnkAddNew" NavigateUrl="CreateWaiver.aspx"><img style="border:0;vertical-align:middle; margin-right:3px;" alt="" src="IMAGES/GridWebBlue/AddRecord.gif" />Create New Waiver</asp:HyperLink> 
                                <asp:HyperLink runat="server" ID="lnkRootCause" NavigateUrl='RootCause.aspx?id=<%# RadGrid1.SelectedValue.ToString() %>' Visible='<%# RadGrid1.EditIndexes.Count == 0 && !RadGrid1.MasterTableView.IsItemInserted  %>'>Root Cause</asp:HyperLink> 
                                <asp:LinkButton ID="cmdRootCause" runat="server" CommandName="RootCause.aspx" Visible='<%# RadGrid1.EditIndexes.Count == 0 && !RadGrid1.MasterTableView.IsItemInserted  %>'><img style="border:0px;vertical-align:middle;" alt="" src="Images/sign_question.png" />Root Cause</asp:LinkButton>&nbsp;&nbsp;  
                                <asp:LinkButton ID="cmdApproval" runat="server" CommandName="ApproveWaiver.aspx" Visible='<%# RadGrid1.EditIndexes.Count == 0 && !RadGrid1.MasterTableView.IsItemInserted %>'><img style="border:0px;vertical-align:middle;" alt="" src="Images/sign_tick.png" />Approve Selected Waiver</asp:LinkButton>&nbsp;&nbsp;  
                                <asp:LinkButton ID="LinkButton1" runat="server" CommandName="CreateWaiver.aspx" Visible='<%# RadGrid1.EditIndexes.Count == 0 && !RadGrid1.MasterTableView.IsItemInserted %>'><img style="border:0px;vertical-align:middle;" alt="" src="Images/window_text.png" />View Details</asp:LinkButton>&nbsp;&nbsp;                              
    <ClientSettings EnablePostBackOnRowClick="true">  
      <Selecting AllowRowSelect="True" /> 

    lnkRootCause is a little different.  the link navigates to another page passing an arg in the querystring.  the arg is the grid.selectedvalue

    the problem is that NavigateURL is not evaluating properly

    its evaluating to ...

    http://localhost:63254/RootCause.aspx?id=<%# RadGrid1.SelectedValue.ToString() %> 

    it would be nice if I could keep this in markup as it makes it simple.

    If there is another more standard way to accomplish this please let me know.

    to summarize I want to  ...

    1) Select a row in grid.
    2) Click a button in CommandItem
    3) Navigate to another page passing variables from the GridDataItem of the selected row in the querystring.

  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 26 May 2010 Link to this post

    Hello KellyRoberts,

    One suggestion would be accessing the Hyperlink control in SelectedIndexChanged event of RadGrid and setting its NavigateUrl as shown below.

     protected void RadGrid1_SelectedIndexChanged(object sender, EventArgs e) 
            GridCommandItem cmditem = (GridCommandItem)RadGrid1.MasterTableView.GetItems(GridItemType.CommandItem)[0]; 
            HyperLink link = (HyperLink)cmditem.FindControl("lnkRootCause"); 
            link.NavigateUrl = "Test12.aspx?id=" + RadGrid1.SelectedValue.ToString(); 

Back to Top