Get Value from Command Arg(ON Item Databound)

4 posts, 0 answers
  1. Chad
    Chad avatar
    10 posts
    Member since:
    Feb 2013

    Posted 07 Mar 2014 Link to this post

    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


  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 10 Mar 2014 in reply to Chad Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Chad
    Chad avatar
    10 posts
    Member since:
    Feb 2013

    Posted 10 Mar 2014 in reply to Shinu Link to this post

    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

     


  5. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 11 Mar 2014 in reply to Chad Link to this post

    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.
Back to Top