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

Get value in row selected

8 Answers 364 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Leandro
Top achievements
Rank 1
Leandro asked on 14 Mar 2012, 07:32 PM
Hello,

I'm trying to get the value of a column in a selected row.
I've tried to do the following:

(VB)
For each Row as GridDataItem in gridMovimento.SelectedItems
Ids += Row("DFid")
Next

So that "" is the count = 0 ...
Can anyone help me? 

Ty...

8 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 15 Mar 2012, 07:56 AM
Hello Leandro,

Please check below links and let me know if you still any issue.

Grid / Client-Side Row Selection
Grid / Server-Side Row Selection


Note : Please check that before you access selected item in RadGrid may be your rebind any where so it lost selected items.

Thanks,
Jayesh Goyani
0
Princy
Top achievements
Rank 2
answered on 15 Mar 2012, 08:02 AM
Hello Leandro,

You can try the following code to access the value of a column in the selected row.
VB:
Protected Sub Button1_Click(sender As Object, e As EventArgs)
    For Each item As GridDataItem In RadGrid1.SelectedItems
        Dim value As String = item("DFid").Text
    Next
End Sub
Seems like you are looking to accomplish something else. Your code looks good to access the particular column value in the row. I would be able to help you better if you could specify the exact scenario & your specific challenge.

Regards,
Princy.
0
Leandro
Top achievements
Rank 1
answered on 15 Mar 2012, 12:45 PM
Prince,

thanks for the return.

My scenario is a simple registration.
The insertion part is working properly.
Now I need help is on the amendment, which I select a record in the grid, click on theChange button and it rolls the dice on the grid for respective fields.

Do not know the reason why my "SelectedItems" is not set, always comes 0.
The stranger also, I tried to do a loop through the items and do the checking if the linewas selected (RadGrid1.Items(i).selected) was to "false" as well. 
0
Princy
Top achievements
Rank 2
answered on 16 Mar 2012, 07:28 AM
Hello,

I suppose you are binding grid in page_load, which clears all the selected items. Add if(!IsPostBack) into the PageLoad to get the selected items.
Another alternative would be to bind the grid with "advanced databinding" using its NeedDataSource event. You can refer to Advanced Data-binding (using NeedDataSource event) for more information on this approach.
I would be able to help you better if you share the code and the exact scenario.

Thanks,
Princy.
0
Leandro
Top achievements
Rank 1
answered on 17 Mar 2012, 11:22 PM
This is my code i'm using for connect to the grid.

--CREATE TABLE GRID -------------------------------------------------------
        tbTempMovtoBancario = "TBtemp_baixa"
        'tbTempMovtoBancario = CriarTB(tbTempMovtoBancario, "Pesquisa")
        strSql = _
            "CREATE TEMPORARY TABLE " & tbTempMovtoBancario & " " & _
                 "( DFid INT(10) unsigned not null auto_increment" & _
                 ", DFvalor DECIMAL(18,2)" & _
                 ", DFid_conta INT" & _
                 ", DFconta VARCHAR(50)" & _
                 ", DFdata_conciliacao DATETIME" & _
                 ", DFcod_tipo_baixa INT" & _
                 ", DFtipo_baixa VARCHAR(50)" & _
                 ", DFnumero VARCHAR(20)" & _
                 ", DFnumero_autenticacao VARCHAR(100) " & _
                 ", DFhistorico VARCHAR(100)" & _
                 ", primary key (DFid)) "
        cmd = New MySqlCommand(strSql, conexao2)
        Try
            conexao.Open()
            cmd.ExecuteScalar()
            conexao.Close()
        Catch ex As Exception
            conexao.Close()
        End Try
 
        strSql = "SELECT * FROM " & tbTempMovtoBancario
        cmd = New MySqlCommand(strSql, conexao)
        da = New MySqlDataAdapter(cmd)
        ds = New DataSet
        da.Fill(ds, tbTempMovtoBancario)
        gridMovimento_Bancario.DataSource = ds
        gridMovimento_Bancario.DataBind()


<
telerik:RadGrid ID="gridMovimento_Bancario" runat="server" AutoGenerateColumns="False"
    CellSpacing="0" GridLines="None" Skin="Outlook" PageSize="5"
    AllowPaging="True" ClientIDMode="Inherit" GroupingEnabled="False"
    AllowMultiRowSelection="true" >
    <PagerStyle Mode="NumericPages" />
    <ClientSettings EnableRowHoverStyle="true" >
        <ClientEvents OnRowSelected="Selecionar_Linha" />
        <Selecting AllowRowSelect="True"></Selecting>                                                   
    </ClientSettings>
 
    <MasterTableView ShowFooter="true" Frame="Border" TableLayout="Auto" Dir="LTR"
        DataKeyNames="DFid" ClientDataKeyNames="DFid" >
        <CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings>
        <RowIndicatorColumn Visible="True" FilterControlAltText="Filter RowIndicator column">
            <HeaderStyle Width="20px"/>
        </RowIndicatorColumn>
        <ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column">
            <HeaderStyle Width="20px"/>
        </ExpandCollapseColumn>
 
        <Columns>
            <telerik:GridBoundColumn DataField="DFnumero"
                FilterControlAltText="Filter DFnumero column" HeaderText="Número"
                UniqueName="DFnumero">
                <HeaderStyle Width="80px" />
                <ItemStyle Width="80px" HorizontalAlign="Right" />
                <FooterStyle Width="80px" />
            </telerik:GridBoundColumn>
            <telerik:GridDateTimeColumn DataField="DFdata_conciliacao"
                FilterControlAltText="Filter DFdata_conciliacao column"
                HeaderText="Disponibilidade" UniqueName="DFdata_conciliacao"
                DataFormatString="{0:dd/MM/yyyy}">
            </telerik:GridDateTimeColumn>
            <telerik:GridBoundColumn DataField="DFcod_tipo_baixa"
                FilterControlAltText="Filter DFcod_tipo_baixa column"
                UniqueName="DFcod_tipo_baixa" Visible="False">
                <ItemStyle Width="0px"/>
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="DFtipo_baixa"
                FilterControlAltText="Filter DFtipo_baixa column" HeaderText="Tipo de Baixa"
                UniqueName="DFtipo_baixa">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="DFid_conta"
                FilterControlAltText="Filter DFid_conta column" UniqueName="DFid_conta"
                Visible="False">
                <ItemStyle Width="0px"/>
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="DFconta"
                FilterControlAltText="Filter DFconta column" HeaderText="Conta"
                UniqueName="DFconta">
            </telerik:GridBoundColumn>
            <telerik:GridNumericColumn AllowRounding="True" DataField="DFvalor"
                DecimalDigits="2" FilterControlAltText="Filter DFvalor column"
                HeaderText="Valor" UniqueName="DFvalor" Aggregate="Sum" FooterText="Total: ">
                <ItemStyle HorizontalAlign="Right" />
                <FooterStyle Font-Bold="true" ForeColor="Blue" HorizontalAlign="Right" />
            </telerik:GridNumericColumn>
            <telerik:GridBoundColumn DataField="DFconta"
                FilterControlAltText="Filter DFconta column" UniqueName="DFconta"
                Visible="False">
                <ItemStyle Width="0px"/>
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="DFnumero_autenticacao"
                FilterControlAltText="Filter DFnumero_autenticacao column"
                UniqueName="DFnumero_autenticacao" Visible="False">
                <ItemStyle Width="0px"/>
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="DFhistorico"
                FilterControlAltText="Filter DFhistorico column" UniqueName="DFhistorico"
                Visible="False">                                   
                <ItemStyle Width="0px"/>
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="DFid"
                FilterControlAltText="Filter DFid column" UniqueName="DFid" Visible="False">
            </telerik:GridBoundColumn>
        </Columns>
 
        <EditFormSettings>
            <EditColumn FilterControlAltText="Filter EditCommandColumn column"></EditColumn>
        </EditFormSettings>
    </MasterTableView>
 
    <FilterMenu EnableImageSprites="False"></FilterMenu>
</telerik:RadGrid>
0
Princy
Top achievements
Rank 2
answered on 19 Mar 2012, 05:58 AM
Hi Leandro,

Try Binding the grid using Advanced Data-binding using its NeedDataSource as follows.

aspx:
<telerik:RadGrid ID="gridMovimento_Bancario" runat="server" AutoGenerateColumns="False"
    CellSpacing="0" GridLines="None" Skin="Outlook" PageSize="5"
    AllowPaging="True" ClientIDMode="Inherit" GroupingEnabled="False"
    AllowMultiRowSelection="true"
            onneeddatasource="gridMovimento_Bancario_NeedDataSource" ></telerik:RadGrid>

VB:
Protected Sub gridMovimento_Bancario_NeedDataSource(sender As Object, e As Telerik.Web.UI.GridNeedDataSourceEventArgs)
 
  tbTempMovtoBancario = "TBtemp_baixa"
        'tbTempMovtoBancario = CriarTB(tbTempMovtoBancario, "Pesquisa")
        strSql = _
            "CREATE TEMPORARY TABLE " & tbTempMovtoBancario & " " & _
                 "( DFid INT(10) unsigned not null auto_increment" & _
                 ", DFvalor DECIMAL(18,2)" & _
                 ", DFid_conta INT" & _
                 ", DFconta VARCHAR(50)" & _
                 ", DFdata_conciliacao DATETIME" & _
                 ", DFcod_tipo_baixa INT" & _
                 ", DFtipo_baixa VARCHAR(50)" & _
                 ", DFnumero VARCHAR(20)" & _
                 ", DFnumero_autenticacao VARCHAR(100) " & _
                 ", DFhistorico VARCHAR(100)" & _
                 ", primary key (DFid)) "
        cmd = New MySqlCommand(strSql, conexao2)
        Try
            conexao.Open()
            cmd.ExecuteScalar()
            conexao.Close()
        Catch ex As Exception
            conexao.Close()
        End Try
  
        strSql = "SELECT * FROM " & tbTempMovtoBancario
        cmd = New MySqlCommand(strSql, conexao)
        da = New MySqlDataAdapter(cmd)
        ds = New DataSet
        da.Fill(ds, tbTempMovtoBancario)
        gridMovimento_Bancario.DataSource = ds
         
End Sub

Thanks,
-Princy.
0
Leandro
Top achievements
Rank 1
answered on 19 Mar 2012, 01:17 PM
Hi Princy,

Thank you, using this event ("NeedDataSource") managed to recover the value of"selectedItems."
I wonder, why not work the other way and that yes, it's because I'm not wearing adatasourcer?
Thank you for your help. 
0
Princy
Top achievements
Rank 2
answered on 20 Mar 2012, 06:38 AM
Hi Leandro,

When you are binding the Grid in page_load without adding (!isPostback), the grid will bind to DataSource whenever a postback occurs(in this case when clicking on a button) and all the selected items gets cleared. There are two options to prevent the selected values getting cleared.

1. You can use if(!IsPostBack) on page_load, then page_load will fire only once, for the first time.
2. NeedDataSource method as shown in the previous post (which is the preferred approach especially if you are performing any advanced operations in RadGrid).

Thanks,
-Princy
Tags
Grid
Asked by
Leandro
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Princy
Top achievements
Rank 2
Leandro
Top achievements
Rank 1
Share this question
or