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

Get Value from Command Arg(ON Item Databound)

3 Answers 236 Views
ToolTip
This is a migrated thread and some comments may be shown as answers.
Chad
Top achievements
Rank 1
Chad asked on 07 Mar 2014, 03:41 PM
Hi,

I was the ToolTip Manager and trying to get the ID from the link button through the command argument but am having difficulty with it.

Below is my code.

----Tool Tip--------

<

 

 

telerik:RadToolTipManager ID="ttManager" runat="server" HideEvent="ManualClose" Width="250" Height="250" EnableShadow="true" OnAjaxUpdate="ttManager_AjaxUpdate" RelativeTo="Element">

 

</telerik:RadToolTipManager>

------Grid Link Btn-----

 

</telerik:GridTemplateColumn>

 

Chad-

<telerik:GridTemplateColumn HeaderText="NOTES" UniqueName="NoteID">

 

<ItemTemplate>

 

<asp:LinkButton ID="lnkNote" runat="server" CommandArgument='<%#Bind("intRSPID")%>' CommandName="Notes">Notes</asp:LinkButton>

 

</ItemTemplate>

 

</telerik:GridTemplateColumn>

 

<telerik:GridBoundColumn DataField="strRSPSiteLocation" HeaderText="RSP SITE" />

 

<

telerik

:

GridBoundColumn

DataField

="strUIC"

HeaderText

="UIC"

/>

------Code Behind--------

 

 

Protected Sub ttManager_AjaxUpdate(ByVal sender As Object, ByVal args As ToolTipUpdateEventArgs)

 

Me.UpdateToolTip(args.Value, args.UpdatePanel)

 

End Sub

 

Private Sub UpdateToolTip(ByVal elementID As String, ByVal panel As UpdatePanel)

 

Dim ctrl As Control = Page.LoadControl("~/Notes.ascx")

panel.ContentTemplateContainer.Controls.Add(ctrl)

 

'Dim details As ProductDetails = DirectCast(ctrl, ProductDetails)

panel.ContentTemplateContainer.Controls.Add(ctrl)

 

End Sub

 

Protected Sub myRadGrid_ItemDataBound(sender As Object, e As GridItemEventArgs) Handles myRadGrid.ItemDataBound

 

If e.Item.ItemType = GridItemType.Item OrElse e.Item.ItemType = GridItemType.AlternatingItem Then

 

Dim RSPID As Integer = e.Item.OwnerTableView.DataKeyValues(e.Item.ItemIndex)("intRSPID")

 

Dim target As Control = e.Item.FindControl("lnkNote")

Session(

 

"NotesID") = RSPID

 

Dim ctrl As Control = Page.LoadControl("~/Notes.ascx")

ctrl.ID = target.ID

 

If Not [Object].Equals(target, Nothing) Then

 

If Not [Object].Equals(Me.ttManager, Nothing) Then

 

'Add the button (target) id to the tooltip manager

 

Me.ttManager.TargetControls.Add(target.ClientID, (TryCast(e.Item, GridDataItem)).GetDataKeyValue("intRSPID").ToString(), True)

 

End If

 

End If

 

End If

 

End Sub

 

Thanks


3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 10 Mar 2014, 06:39 AM
Hi Chad,

I guess that you want to access the CommandArgument of LinkButton in RadGrid OnItemDataBound event. Please have a look into the sample code snippet which works fine at my end.

ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="SqlDataSource1" OnItemDataBound="RadGrid1_ItemDataBound">
    <MasterTableView>
        <Columns>
            <telerik:GridTemplateColumn UniqueName="CustomerID" HeaderText="CustomerID">
                <ItemTemplate>
                    <asp:LinkButton ID="LinkButton1" runat="server" CommandName="CustomerID" CommandArgument='<%#Bind("CustomerID")%>' >CustomerID
                    </asp:LinkButton>
                </ItemTemplate>
            </telerik:GridTemplateColumn>
        </Columns>
    </MasterTableView>
</telerik:RadGrid>

VB:
Protected Sub RadGrid1_ItemDataBound(sender As Object, e As Telerik.Web.UI.GridItemEventArgs)
    If TypeOf e.Item Is GridDataItem Then
        Dim dataItem As GridDataItem = DirectCast(e.Item, GridDataItem)
        Dim button As LinkButton = DirectCast(dataItem.FindControl("LinkButton1"), LinkButton)
        Dim commandargument As String = button.CommandArgument
    End If
End Sub

Please elaborate your requirement if it doesn't help.
Thanks,
Shinu.
0
Chad
Top achievements
Rank 1
answered on 10 Mar 2014, 02:05 PM
I used the provided snippet and it does work but it still grabs the DataKeyValue of the last Row.  It runs through every row on the page load and runs through all the datakeyvalues but when I call the Tooltipmanager web service it always shows the notes of the last row for every row.  Hope this makes sense and if you have any more questions let me know.

Below is my updated code.

 

<telerik:GridTemplateColumn HeaderText="NOTES" UniqueName="NoteID">

 

<ItemTemplate>

 

<asp:LinkButton ID="lnkNote" runat="server" CommandArgument='<%#Bind("intRSPID")%>' CommandName="Notes">Notes</asp:LinkButton>

 

</ItemTemplate>

 

</

telerik

:

GridTemplateColumn

>

code behind

 

 

Protected Sub ttManager_AjaxUpdate(ByVal sender As Object, ByVal args As ToolTipUpdateEventArgs)

 

Me.UpdateToolTip(args.Value, args.UpdatePanel)

 

End Sub

 

Private Sub UpdateToolTip(ByVal elementID As String, ByVal panel As UpdatePanel)

 

Dim ctrl As Control = Page.LoadControl("~/Notes.ascx")

panel.ContentTemplateContainer.Controls.Add(ctrl)

 

'Dim details As ProductDetails = DirectCast(ctrl, ProductDetails)

panel.ContentTemplateContainer.Controls.Add(ctrl)

 

End Sub

 

Protected Sub myRadGrid_ItemDataBound(sender As Object, e As GridItemEventArgs) Handles myRadGrid.ItemDataBound

 

If e.Item.ItemType = GridItemType.Item OrElse e.Item.ItemType = GridItemType.AlternatingItem Then

 

Dim dataItem As GridDataItem = DirectCast(e.Item, GridDataItem)

 

Dim button As LinkButton = DirectCast(dataItem.FindControl("lnkNote"), LinkButton)

 

Dim RSPID As String = button.CommandArgument.ToString

 

Dim target As Control = e.Item.FindControl("lnkNote")

Session(

 

"NotesID") = RSPID

 

Dim ctrl As Control = Page.LoadControl("~/Notes.ascx")

ctrl.ID = target.ID

 

If Not [Object].Equals(target, Nothing) Then

 

If Not [Object].Equals(Me.ttManager, Nothing) Then

 

'Add the button (target) id to the tooltip manager

 

Me.ttManager.TargetControls.Add(target.ClientID, (TryCast(e.Item, GridDataItem)).GetDataKeyValue("intRSPID").ToString(), True)

 

End If

 

End If

 

End If

 

End Sub

 


0
Shinu
Top achievements
Rank 2
answered on 11 Mar 2014, 07:12 AM
Hi Chad,

I am not sure about your requirement. Please have a look into this online demo to show the RadToolTip in LinkButton which is inside the ItemTemplate of RadGrid.

Thanks,
Shinu.
Tags
ToolTip
Asked by
Chad
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Chad
Top achievements
Rank 1
Share this question
or