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

RadGrid with linkbutton on each row

6 Answers 200 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Myriam
Top achievements
Rank 1
Myriam asked on 17 Sep 2008, 01:20 PM
Hello all
I'm new with telerik. What I want to do is basic but I just didn't find how to do it.
I have a radgrid with MasterTableView and one DetailTable. On each row of my detail table I have a linkbutton. What I want to do is to get the value of the first column on my detailtable of the row I just clicked on, on the code-behind. I tried many event but I couldn't find which one was the right one and how to get the value of my first column.
Please help
this is my code

<

telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="True"

AllowSorting="True" DataSourceID="CustomerSource" GridLines="None"

AutoGenerateColumns="False">

<MasterTableView datasourceid="CustomerSource" DataKeyNames="NO_FOURNISSEUR">

<RowIndicatorColumn Visible="False">

<HeaderStyle Width="20px"></HeaderStyle>

</RowIndicatorColumn>

<ExpandCollapseColumn Visible="False" Resizable="False">

<HeaderStyle Width="20px"></HeaderStyle>

</ExpandCollapseColumn>

<EditFormSettings>

<PopUpSettings ScrollBars="None"></PopUpSettings>

</EditFormSettings>

<Columns>

<telerik:GridBoundColumn SortExpression="NO_FOURNISSEUR"

HeaderText="NO_FOURNISSEUR"

DataField="NO_FOURNISSEUR"

UniqueName="NO_FOURNISSEUR"

ReadOnly="true"

Visible="true">

</telerik:GridBoundColumn>

<telerik:GridBoundColumn SortExpression="NOM"

HeaderText="NOM"

DataField="NOM"

UniqueName="NOM"

ReadOnly="true"

Visible="true">

</telerik:GridBoundColumn>

</Columns>

<DetailTables>

<telerik:GridTableView DataKeyNames="No_fournisseur_produit" DataSourceID="PanierItemSource" >

<ParentTableRelation>

<telerik:GridRelationFields DetailKeyField="NO_FOURNISSEUR" MasterKeyField="NO_FOURNISSEUR" />

</ParentTableRelation>

<Columns>

<telerik:GridBoundColumn SortExpression="No_fournisseur_produit"

HeaderText="No fournisseur produit"

DataField="No_fournisseur_produit"

UniqueName="No_fournisseur_produit"

ReadOnly="true"

Visible="true">

</telerik:GridBoundColumn>

<telerik:GridButtonColumn ButtonType=LinkButton UniqueName="LkConfirmer" CommandName="ConfirmerUnItem" Text="Confirmer">

</telerik:GridButtonColumn>

</Columns>

</telerik:GridTableView>

</DetailTables>

</MasterTableView>

</telerik:RadGrid>

Thanks in advance

6 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 17 Sep 2008, 02:13 PM
Hello Myriam,

You can check for the CommndName of the Button in the ItemCommand and then check for the OwnerTableView using its Name property and get the cell value as shown in the code below.
aspx:
<telerik:GridTableView DataKeyNames="No_fournisseur_produit" DataSourceID="PanierItemSource" Name="Detail" > 
  

cs:
 protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e) 
    { 
 
          if (e.CommandName == "ConfirmerUnItem")  
        {  
            if (e.Item.OwnerTableView.Name == "Detail")  
            { 
                GridDataItem item = (GridDataItem)e.Item; 
                string strtxt = item["No_fournisseur_produit"].Text; 
            }  
        }  
    } 

Princy.

0
Myriam
Top achievements
Rank 1
answered on 17 Sep 2008, 02:48 PM
Thank you Princy for your help.
Sorry, I forgot to say that I use vb instead of c
And I don't know how to change the code c to vb as I don't know the c language...
Thank you in advance
0
Myriam
Top achievements
Rank 1
answered on 17 Sep 2008, 03:07 PM
Hi
Me again. I found how to change you c code to vb code. I still don't get the result I want. I put a break point on the Private Sub line and it doesn't pass there when I click on my linkbutton as it didn't stop to my break point.

Here is the code behind

Private Sub RadGrid1_ItemCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.ItemCommand

Dim item As GridDataItem

Dim strtxt As String

If e.CommandName = "ConfirmerUnItem" Then

If e.Item.OwnerTableView.Name = "Detail" Then

item =

CType(e.Item, GridDataItem)

strtxt = item(

"No_fournisseur_produit").Text

End If

End If

End Sub

0
Shinu
Top achievements
Rank 1
answered on 18 Sep 2008, 04:29 AM
Hi Myriam,

The above given code is working correctly on my end. Have you set the event handler for the ItemCommand event? Also verify that the Name property for the Detail table is properly set.

Regards
Shinu.
0
Myriam
Top achievements
Rank 1
answered on 18 Sep 2008, 12:43 PM

Hello
Thanks Shinu for trying to help me.
First, I don't understand when you say "Have you set the event handler for the ItemCommand event?"

So here is my code. The event itemCommand doesn't start when I click on my linkButton. Remember that my linkbutton is on the detail table. Maybe I need something more I don't know.

Shinu, you tried the code with a linkbutton on the detailtable and not on the master table and it did work?

I don't know if it changes something but when I load my page, I see only the master table, then I have to click on the master table arrow (at the left on each row) to make appear the detail table.

Ok this is my code

.aspx.vb

Public

Sub RadGrid1_ItemCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.ItemCommand

Dim item As GridDataItem

Dim strtxt As String

If e.CommandName = "ConfirmerUnItem" Then

If e.Item.OwnerTableView.Name = "Detail" Then

item =

CType(e.Item, GridDataItem)

strtxt = item(

"No_fournisseur_produit").Text

End If

End If

End Sub



and here is my aspx



<telerik:RadGrid DataSourceID="CustomerSource"

ID="RadGrid1"

autogeneratecolumns=false

runat="server">

<MasterTableView datasourceid="CustomerSource" DataKeyNames="NO_FOURNISSEUR">

<Columns>

<telerik:GridBoundColumn SortExpression="NO_FOURNISSEUR"

HeaderText="NO_FOURNISSEUR"

DataField="NO_FOURNISSEUR"

UniqueName="NO_FOURNISSEUR"

ReadOnly="true"

Visible="true">

</telerik:GridBoundColumn>

<telerik:GridBoundColumn SortExpression="NOM"

HeaderText="NOM"

DataField="NOM"

UniqueName="NOM"

ReadOnly="true"

Visible="true">

</telerik:GridBoundColumn>

</Columns>

<DetailTables>

<telerik:GridTableView DataKeyNames="No_fournisseur_produit" DataSourceID="PanierItemSource" Name="Detail" >

<ParentTableRelation>

<telerik:GridRelationFields DetailKeyField="NO_FOURNISSEUR" MasterKeyField="NO_FOURNISSEUR" />

</ParentTableRelation>

<Columns>

<telerik:GridButtonColumn ButtonType=LinkButton UniqueName="LkConfirmer" CommandName="ConfirmerUnItem" Text="Confirmer">

</telerik:GridButtonColumn> 

<

telerik:GridBoundColumn SortExpression="No_fournisseur_produit"

HeaderText="No fournisseur produit"

DataField="No_fournisseur_produit"

UniqueName="No_fournisseur_produit"

ReadOnly="true"

Visible="true">

</telerik:GridBoundColumn>

</Columns>

<EditFormSettings>

<PopUpSettings ScrollBars="None"></PopUpSettings>

</EditFormSettings>

</telerik:GridTableView>

</DetailTables>

</MasterTableView>

</telerik:RadGrid>

0
Accepted
Shinu
Top achievements
Rank 1
answered on 19 Sep 2008, 04:31 AM
Hi,

Yea I did try with the Detail table. Here is the code which I tried on my end  and it is working as expected.

ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server"  DataSourceID="SqlDataSource1"  OnItemCommand="RadGrid1_ItemCommand" > 
           
 
  <MasterTableView AutoGenerateColumns="False"   Name="Master"  DataSourceID="SqlDataSource1"
               
                 
                <Columns> 
                     
                    <telerik:GridBoundColumn DataField="SupplierID" DataType="System.Int32" HeaderText="SupplierID" 
                        SortExpression="SupplierID" UniqueName="SupplierID"
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn DataField="CategoryID" DataType="System.Int32" HeaderText="CategoryID" 
                        SortExpression="CategoryID" UniqueName="CategoryID"
                    </telerik:GridBoundColumn> 
                    
                </Columns> 
                
                 
                <DetailTables> 
                  <telerik:GridTableView runat="server"   Name="Detail" DataSourceID="SqlDataSource1" > 
                    <Columns> 
                     <telerik:GridBoundColumn DataField="ProductName" HeaderText="ProductName" SortExpression="ProductName" 
                        UniqueName="ProductName"
                    </telerik:GridBoundColumn> 
                     <telerik:GridButtonColumn UniqueName="BtnCol" HeaderText="BtnCol" Text="MyCommand" CommandName="MyCommand" ></telerik:GridButtonColumn> 
                   
                    </Columns> 
                     
                  </telerik:GridTableView> 
                </DetailTables> 
            </MasterTableView> 
            
        </telerik:RadGrid><br /> 

VB:
Protected Sub RadGrid1_ItemCommand(ByVal source As Object, ByVal e As GridCommandEventArgs) 
     If (e.CommandName = "MyCommand") AndAlso (e.Item.OwnerTableView.Name = "Detail") Then 
        Dim item As GridDataItem = DirectCast(e.Item, GridDataItem) 
         Dim strtxt As String = item("ProductName").Text.ToString() 
     End If 
 End Sub 


Thanks
Shinu
Tags
Grid
Asked by
Myriam
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Myriam
Top achievements
Rank 1
Shinu
Top achievements
Rank 1
Share this question
or