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

[Solved] Find gridrow by datakeyvalue

3 Answers 111 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Joe Terhune
Top achievements
Rank 2
Joe Terhune asked on 24 Sep 2009, 12:35 PM
I have a radgrid like below with a column that adds a document to a shopping Cart by clicking a hyperlink.  When the document is added the link is hidden so that the document cannot be added again.  When the document is removed from the cart, I want to find the row in the radgrid based on the documentId  and show the link again. I found how to get row here now I need to hide hyperlink in column. I want to be able to do this client-side.

<telerik:RadGrid ID="rgResults" runat="server">  
                    <MasterTableView DataKeyNames="DocumentId" ClientDataKeyNames="DocumentId" DataSourceID="linqSource" 
                        AutoGenerateColumns="false">  
                        <Columns> 
                            <telerik:GridBoundColumn DataField="CaseNumber" HeaderText="Case Number" UniqueName="CaseNumber" /> 
                            <telerik:GridBoundColumn DataField="ParcelId" HeaderText="Parcel Id" UniqueName="ParcelId" /> 
                            <telerik:GridBoundColumn DataField="PartyName" HeaderText="Party Name" UniqueName="PartyName" /> 
                            <telerik:GridTemplateColumn UniqueName="AddDocument" HeaderText="Add">  
                                <ItemTemplate> 
                                    <asp:HyperLink ID="lnkAddDoc" runat="server" NavigateUrl='<%#"DocumentCart.aspx?docId=" & Eval("DocumentId") %>'>  
                                        <asp:Image ID="lnkImgAddDoc" runat="server" ImageUrl="~/images/doc.gif" AlternateText="Add to My Documents" /></asp:HyperLink> 
                                </ItemTemplate> 
                                <ItemStyle Width="25px" /> 
                            </telerik:GridTemplateColumn> 
                        </Columns> 
                    </MasterTableView> 
                </telerik:RadGrid> 

 

3 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 24 Sep 2009, 01:27 PM
Hello Jterhune,

You can try out the following code to hide or show the hyperlink on the client:
js:
 
 function show()  
    {     
       var Rows = $find("<%=rgResults.ClientID %>").get_masterTableView().get_dataItems();  
       for (var i = 0; i < Rows.length; i++)  
       {  
         var row = Rows[i];  
         if(row.getDataKeyValue("DocumentId")=="5")  
         {  
            var hyperlink = row.findElement("lnkAddDoc");  
            hyperlink.style.display="none"// to hide  
            // hyperlink.style.display="block"; // to show  
         }  
       }    
    }  

Thanks
Princy.
0
Joe Terhune
Top achievements
Rank 2
answered on 24 Sep 2009, 02:05 PM
row.findElement("lnkAddDoc");  returns undefined.  Is it because lnkAddDoc is not the clientId?
0
Joe Terhune
Top achievements
Rank 2
answered on 24 Sep 2009, 02:32 PM
My mistake that does work. Damn case sensitive JavaScript. I had the ClientDayaKeyNames value as "DocumentId" and was referencing it as "documentId" in the javascript.
Tags
Grid
Asked by
Joe Terhune
Top achievements
Rank 2
Answers by
Princy
Top achievements
Rank 2
Joe Terhune
Top achievements
Rank 2
Share this question
or