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

Get Cell text in sub grid and lock out linkbutton

5 Answers 130 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kevin
Top achievements
Rank 1
Kevin asked on 08 Feb 2012, 07:46 PM
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>


5 Answers, 1 is accepted

Sort by
0
Kevin
Top achievements
Rank 1
answered on 08 Feb 2012, 09:45 PM
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
0
Shinu
Top achievements
Rank 2
answered on 09 Feb 2012, 05:44 AM
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.
0
Kevin
Top achievements
Rank 1
answered on 09 Feb 2012, 02:53 PM
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. 
0
Kevin
Top achievements
Rank 1
answered on 09 Feb 2012, 04:46 PM
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?????
0
Accepted
Shinu
Top achievements
Rank 2
answered on 10 Feb 2012, 05:18 AM
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.
Tags
Grid
Asked by
Kevin
Top achievements
Rank 1
Answers by
Kevin
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Share this question
or