This is a migrated thread and some comments may be shown as answers.

CommandItem Hyperlink NavigateUrl SelectedGridItem

1 Answer 141 Views
Grid
This is a migrated thread and some comments may be shown as answers.
kellyroberts
Top achievements
Rank 1
kellyroberts asked on 25 May 2010, 03:45 PM
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.

                    <CommandItemTemplate> 
                        <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;                              
                        </div> 
                    </CommandItemTemplate> 
                     
<ClientSettings EnablePostBackOnRowClick="true">  
  <Selecting AllowRowSelect="True" /> 
</ClientSettings> 


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.




1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 26 May 2010, 02:51 PM
Hello KellyRoberts,

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

C#:
  
 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(); 
    } 

Regards,
Shinu.
Tags
Grid
Asked by
kellyroberts
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or