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

[Solved] Trying to get a value from a linkbutton...

1 Answer 204 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kevin J
Top achievements
Rank 1
Kevin J asked on 01 Jun 2009, 09:52 PM

Hello,

  In my codebehind I am creating a Radgrid and adding the columns to the grid.  One of those columns is a GridButtonColumn.  The code looks like so...

 
                    Dim clmbtnGRDMAIN1 As New Telerik.Web.UI.GridButtonColumn  
                    clmbtnGRDMAIN1.DataTextField = rowCOLUMN.FIELDNAME  
                    clmbtnGRDMAIN1.HeaderText = rowCOLUMN.EXTERNAL_READABLE1  
                    clmbtnGRDMAIN1.UniqueName = rowCOLUMN.FIELDNAME  
                    clmbtnGRDMAIN1.HeaderStyle.Width = rowCOLUMN.GRIDWIDTH  
                    clmbtnGRDMAIN1.CommandName = "TEMPID" 
                    grdMAIN1.Columns.Add(clmbtnGRDMAIN1) 

 

 

 

 

This works fine, it creates the button with the proper information.  But what I want to do, is that after a user clicks on the link button, gather the value.

The Telerik example says to put some code in the ItemCreated event.  Such as this...

 

 

 

 

   
 
        If e.Item.ItemType = Telerik.Web.UI.GridItemType.Item Then 
            Dim item As Telerik.Web.UI.GridDataItem  
            item = e.Item  
            Dim LinkButton1 As LinkButton  
            LinkButton1 = item("TEMPID").Controls.Item(0)  
            LinkButton1.CommandArgument = e.Item.ItemIndex.ToString()  
        End If 

 

 

 

 

This works and the index is correct.

But, when I try to get the value in the ItemCommand event, I get nothing.  The code is here...

            Dim index As Integer = Convert.ToInt32(e.CommandArgument)  
 
            Dim item As Telerik.Web.UI.GridDataItem = grdMAIN1.Items(index) 

 

 

 

 

 

 


And if I then do a Response.Write(item("TEMPID").Text, -1)  it comes up with a space when it should contain a string of numbers.

Anyone have any idea what I'm doing wrong or how I can get this value properly?  I'm having a heck of a time trying to do this.  I feel as though it should be easier to get a value out of a link.

Thanks
Kevin

 

 

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 02 Jun 2009, 06:24 AM
Hi Kevin,

You can check for the CommandName and directly access the GridDataItem in the ItemCommand event as shown below.

VB:
 
 
 
 
    Protected Sub RadGrid1_ItemCommand(ByVal source As ObjectByVal e As GridCommandEventArgs) 
        
        If e.CommandName = "TEMPID" Then 
            'to get the GridDataItem 
            Dim item As GridDataItem = DirectCast(e.Item, GridDataItem) 
            
            'to get the text of the clicked buuton 
            Response.Write(DirectCast(e.CommandSource, LinkButton).Text) 
        End If 
   End Sub 
 
 

Thanks
Shinu
Tags
Grid
Asked by
Kevin J
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or