Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET AJAX > Grid > Get Cell text in sub grid and lock out linkbutton

Answered Get Cell text in sub grid and lock out linkbutton

Feed from this thread
  • Kevin Intermediate avatar

    Posted on Feb 8, 2012 (permalink)

    I have a main grid that load with a detailGrid.

    The detail grid has a 2 link buttons and some information from the transfer or repair process.  Depending on the Id of the person whom is logged in I want to be able to hide one or the other link button.  How can I accomplish this.  So basically if joe is logged in an he iniated the transfer process the link button for accept should not show in the detailgrid only the cancel linkbutton.  I am assuming I would take care of this in the databound event but I do not know how to get into the detail grid rows to lock these link buttons out.

    <telerik:RadGrid ID="myIssueGrid" runat="server" Width="95%" BorderWidth="1px" CellPadding="6" GridLines="None" BorderColor="#404040" Skin="Web20">
                                        <MasterTableView AutoGenerateColumns="false" DataKeyNames="intIssuedID" HierarchyDefaultExpanded="false" HierarchyLoadMode="ServerBind" 
                                            BorderColor="#404040" Font-Size="12" Font-Names="Veranda,arial,sans-serif" HeaderStyle-HorizontalAlign="Center" 
                                            GridLines="Both" BorderWidth="1px" ExpandCollapseColumn-ButtonType="ImageButton" ExpandCollapseColumn-CollapseImageUrl="~/Images/30.png" 
                                            ExpandCollapseColumn-ExpandImageUrl="~/Images/29.png"><ItemStyle HorizontalAlign="Center" />
                                            <AlternatingItemStyle BackColor="#B0C4DE"  HorizontalAlign="Center" />
                                            <HeaderStyle ForeColor="White" Font-Bold="true" BorderColor="#404040" BorderWidth="1px" />
                                            <DetailTables>
                                                <telerik:GridTableView Name="myReIssueGrid" runat="server" DataKeyNames="intReIssueId" TableLayout="Fixed" BorderWidth="1px" CellPadding="6" Font-Size="10"
                                                    AutoGenerateColumns="False" HeaderStyle-HorizontalAlign="Center" BorderColor="#404040" Font-Names="Veranda,arial,sans-serif" GridLines="Both" ExpandCollapseColumn-ButtonType="ImageButton"
                                                    ExpandCollapseColumn-CollapseImageUrl="~/Images/30.png" ExpandCollapseColumn-ExpandImageUrl="~/Images/29.png">
                                                    <ParentTableRelation>
                                                        <telerik:GridRelationFields DetailKeyField="intIssuedID" MasterKeyField="intIssuedID" />
                                                    </ParentTableRelation>
                                                    <HeaderStyle Font-Bold="true" HorizontalAlign="Center" CssClass="MostInnerHeaderStyle" />
                                                    <ItemStyle CssClass="MostInnerItemStyle" HorizontalAlign="Center" />
                                                    <AlternatingItemStyle CssClass="MostInnerAlernatingItemStyle" HorizontalAlign="Center" />
                                                    <Columns>
                                                        <telerik:GridTemplateColumn HeaderText="Accept" ItemStyle-HorizontalAlign="Center">
                                                            <ItemTemplate>
                                                                 <asp:LinkButton ID="lnkAccept" runat="server" CommandArgument='<%# bind("intReIssueId") %>' CommandName="Accept">Accept</asp:LinkButton>
                                                            </ItemTemplate>
                                                        </telerik:GridTemplateColumn>
                                                        <telerik:GridTemplateColumn HeaderText="Cancel" ItemStyle-HorizontalAlign="Center">
                                                            <ItemTemplate>
                                                                 <asp:LinkButton ID="lnkCancel" runat="server" CommandArgument='<%# bind("intReIssueId") %>' CommandName="Cancel">Cancel</asp:LinkButton>
                                                            </ItemTemplate>
                                                        </telerik:GridTemplateColumn>
                                                        <telerik:GridBoundColumn DataField="IssueBy" HeaderText="ISSUED FROM" ItemStyle-Font-Size="Smaller" />
                                                        <telerik:GridBoundColumn DataField="IssueTo" HeaderText="ISSUED TO"  ItemStyle-Font-Size="Smaller" />
                                                        <telerik:GridBoundColumn DataField="dtIssue" HeaderText="DT_ISSUED" />
                                                        <telerik:GridBoundColumn DataField="strTransaction" HeaderText="STATUS" />
                                                        <telerik:GridBoundColumn DataField="dtSign" HeaderText="DT_SIGNED" />
                                                    </Columns>
                                                </telerik:GridTableView>
                                            </DetailTables>
                                             <Columns>
                                                 <telerik:GridTemplateColumn HeaderText="Transfer" ItemStyle-HorizontalAlign="Center">
                                                    <ItemTemplate>
                                                            <asp:LinkButton ID="lnkTransfer" runat="server" CommandArgument='<%# bind("intIssuedID") %>' CommandName="Transfer">
                                                            <asp:Image ID="imgReturn" runat="server" ImageUrl="~/Images/Transfer.png" BorderStyle="None" /></asp:LinkButton>
                                                    </ItemTemplate>
                                                </telerik:GridTemplateColumn>
                                                <telerik:GridBoundColumn HeaderText="SN" DataField="strSN" />
                                                <telerik:GridBoundColumn HeaderText="STATUS" DataField="strTransaction" />
                                                <telerik:GridBoundColumn HeaderText="ITEM" DataField="Item" />
                                                <telerik:GridBoundColumn HeaderText="DT_ISSUED" DataField="DT_Issued" />
                                                <telerik:GridBoundColumn HeaderText="DT_SIGNED" DataField="Dt_Signed" />
                                                <telerik:GridBoundColumn HeaderText="QTY" DataField="ftQTY" />
                                            </Columns>
                                        </MasterTableView>
                                    </telerik:RadGrid>


    Reply

  • Kevin Intermediate avatar

    Posted on Feb 8, 2012 (permalink)

    ok, i put together this code for locking out a link button based on label text or I put a label as hideen field inside a template and am getting the value but when the grid renders the link button is still there if it meets the requirements, but when i pick one and it posts back all are then gone off the screen.  is not working like it should I even tried rotoating through the grid but this did not work either.
     If e.Item.OwnerTableView.Name = "myIssueGrid" Then
                If TypeOf e.Item Is GridDataItem Then
                    Dim Item As GridDataItem = DirectCast(e.Item, GridDataItem)
                    Dim lbl As TableCell = Item("strTransaction")
                    Dim Trans As LinkButton = DirectCast(Item.FindControl("lnkTransfer"), LinkButton)
                    Dim tType As Label = DirectCast(Item.FindControl("lbltranstype"), Label)
                    Dim image As Image = DirectCast(Item.FindControl("imgReturn"), Image)
                    Dim type As Integer
                    Type = Convert.ToInt32(tType.Text)
                    If type = 6 Or tType.Text = "TRANSFER" Then
                        Trans.Enabled = False
                        image.Visible = False
                    End If
                End If
            End If

    Reply

  • Posted on Feb 8, 2012 (permalink)

    Hello Kevin,

    Try the following code.
    VB:
    Protected Sub RadGrid1_ItemDataBound(sender As Object, e As Telerik.Web.UI.GridItemEventArgs)
     If TypeOf e.Item Is GridDataItem AndAlso e.Item.OwnerTableView.Name = "myReIssueGrid" Then
      Dim item As GridDataItem = DirectCast(e.Item, GridDataItem)
      Dim cell As TableCell = DirectCast(item("strTransaction"), TableCell)
      Dim link As LinkButton = DirectCast(item.FindControl("lnkTransfer1"), LinkButton)
      If cell.Text = "TRANSFER" Then
       link.Visible = False
      End If
     End If
    End Sub

    -Shinu.

    Reply

  • Kevin Intermediate avatar

    Posted on Feb 9, 2012 (permalink)

    hi thanks but does not work.  Like I posted above the code I have works for the sub detail grid and hides everything and works well, but for the main grid nothing works, no link buttons are hidden.  It is very strange, it seems to not even get into the code because I tried changing the text of the link button but does not change, no making it invisible or disabling it. 

    Reply

  • Kevin Intermediate avatar

    Posted on Feb 9, 2012 (permalink)

    ok so I found a major flaw in the grid when looking at grid names.  For sub grid this code works fine and finds the names of the grids but it does not find the main grids name.  So I am trying to find

    myIssueGrid  (Name of main grid)

    and
    myReIssueGrid (name of detail grid)  Code

    If (e.Item.OwnerTableView.Name = "myReIssueGrid") Then  (Works fine for sub grid)
    but

    For main grid I have to do this <> to sub grid

    If (e.Item.OwnerTableView.Name <> "myReIssueGrid") Then
    this code gets into the main grid and then its able to see the commands I am doing. 

    So why is this?????

    Reply

  • Answer Shinu MVP avatar

    Posted on Feb 9, 2012 (permalink)

    Hello Kevin,

    In order to access the controls in MasterTableView, you can set the Name for the MasterTableView and check for the condition as shown below.
    VB:
    Protected Sub myIssueGrid_ItemDataBound(sender As Object, e As Telerik.Web.UI.GridItemEventArgs)
                'condition for checking  MasterTableView
     If TypeOf e.Item Is GridDataItem AndAlso e.Item.OwnerTableView.Name = "MasterTable" Then
     End If
    End Sub

    -Shinu.

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET AJAX > Grid > Get Cell text in sub grid and lock out linkbutton
Related resources for "Get Cell text in sub grid and lock out linkbutton"

ASP.NET Grid Features  |  Documentation  |  Demos  |  Telerik TV  |  Self-Paced Trainer  |  Step-by-step Tutorial  ]