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

RadGrid + FormView

6 Answers 254 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Joan
Top achievements
Rank 1
Joan asked on 11 Apr 2012, 09:50 AM
Hi!

Sorry about my english -.-'

I have a little issue with one radgrid into formview, i'm trying to retrieve all columns values and i can't, i tried javascript, and visual basic functions in code behind, and always have the same problem, can't find the radgrid , because it is into the formview (i think).

Can anyone suggest something? i've been stuck for too long with this =(

Thanks.

6 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 11 Apr 2012, 10:53 AM
Hi Joan,

Please take a look into the sample code snippet I tried to access the RadGrid inside FormView.

ASPX:
<asp:FormView ID="formview1" runat="server" DefaultMode="Insert">
 <InsertItemTemplate>
    <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1">
      <MasterTableView>
        <Columns>
         <telerik:GridBoundColumn HeaderText="EmployeeID" DataField="EmployeeID" UniqueName="EmployeeID" />
        <telerik:GridBoundColumn HeaderText="LastName" DataField="LastName" UniqueName="LastName" />
       </Columns>
      </MasterTableView>
    </telerik:RadGrid>
 </InsertItemTemplate>
</asp:FormView>

C#:
protected void Page_Load(object sender, EventArgs e)
{
    FormViewRow row = formview1.Row;
    RadGrid r1 = (RadGrid)row.FindControl("RadGrid1");
    foreach (GridDataItem item in r1.Items)
    {
        TableCell cell = (TableCell)item["EmployeeID"];
    }    
}

Thanks,
Shinu.
0
Joan
Top achievements
Rank 1
answered on 11 Apr 2012, 12:02 PM
Thank you a lot, but not working for me, i'll attach my rad grid, and if you can... my code behind is wroten in vb =(
<EditItemTemplate>
                             
                           <uc1:ToolBarActualizar ID="ToolBarActualizar1" runat="server" />  
  
                       <div id="TablaContenidos" >
                            <div class="titulo">
                                <asp:Label ID="Label1" runat="server" CssClass="TitolsPanells" Text="Datos Empresa "></asp:Label>
                                <asp:Label ID="Label2" runat="server" CssClass="TitolsPanellsSecundari" Text="( Editando Empresa )"></asp:Label>       
                            </div>
                        </div>
                       <table id="DivVisites">
                        <tr>
                            <td class="style1" width="30%"></td>
                            <td valign="top">
                            <asp:Panel id="Panel1" runat="server" CssClass="auto-style2" Height="200px" 
                            Width="500px" BorderStyle="Outset" BorderWidth="2px" BackColor="#EEEEEE" 
                            BorderColor="#CCCCCC" HorizontalAlign="Center" >
                                        <table class="auto-style1" style="width: 373px; height: 180px">
                                            <tr>    
                                                <td>
                                                    <asp:Label ID="LblInstalacion" runat="server" CssClass="labelCampo" Text="Código Instalación"></asp:Label>
                                                </td>
                                                <td  align="left">
                                                                <telerik:RadComboBox ID="RCBD" runat="server" Filter="Contains" MarkFirstMatch="true" ChangeTextOnKeyBoardNavigation="false" CssClass="CampoCalculado"
                                                                           DataSourceID="SQL1" DataTextField="Instalacion" DataValueField="CodigoInstalacion" SelectedValue='<%# Bind("CodigoInstalacion") %>' Enabled="false" />
                                                      
  
                                                    <asp:SqlDataSource ID="sql1" runat="server" ConnectionString='<%$ ConnectionStrings:VisSecConnectionString1 %>'
                                                                       SelectCommand="SELECT    Departamentos.*, Instalaciones.Instalacion, Instalaciones.CodigoInstalacion AS Expr1
                                                                                      FROM            Departamentos INNER JOIN    
                                                                                      Instalaciones ON Departamentos.CodigoInstalacion = Instalaciones.CodigoInstalacion">
                                                    </asp:SqlDataSource>
                                                  
                                                      
                                                </td>
                                            </tr>
                                            <tr>    
                                                <td>
                                                    <asp:Label ID="lblEmpresa" runat="server" CssClass="labelCampo" Text="Código Empresa"></asp:Label>
                                                </td>
                                                <td align="left">
                                                <telerik:RadNumericTextBox id="txtEmpresa" runat="server" width="200" ReadOnly="true" enabled="false" text='<%#Bind ("CodigoEmpresa") %>' NumberFormat-GroupSeparator="" NumberFormat-DecimalDigits="0" />
                                                      
                                                </td>
                                            </tr>
                                            <tr>    
                                                <td>
                                                    <asp:Label ID="lblNombreEmpresa" runat="server" CssClass="labelCampo" Text="Nombre Empresa"></asp:Label>
                                                </td>
                                                <td align="left">
                                                    <telerik:RadTextBox id="txtNombreEmpresa" runat="server" width="200" text='<%#Bind ("DescripcionEmpresa") %>' NumberFormat-GroupSeparator="" NumberFormat-DecimalDigits="0" />
                                                     
                                                </td>
                                            </tr>
                                            <tr>    
                                                <td>
                                                    <asp:Label ID="lblVisitadoExtension" runat="server" CssClass="labelCampo" Text="Empresa del Grupo"></asp:Label>
                                                </td>
                                                <td align="left" >
                                                    <asp:CheckBox ID="txtVisitadoExtension" runat="server"  Checked='<%#Bind("EmpresaDelGrupo") %>'></asp:CheckBox>
                                                      
                                                </td>
                                                </tr>
                                        </table>
                                </asp:Panel>        
                              </td>
                             </tr>
                         </table>
                         </EditItemTemplate>

this is the edit template from the formview
 
Thanks a lot.
0
Shinu
Top achievements
Rank 2
answered on 12 Apr 2012, 06:55 AM
Hello Joan,

I cannot find any RadGrid declaration from your code. Here is the code that I tried to access the RadTextBox in Panel. Please elaborate your scenario if it doesn't help.
VB:
Protected Sub Page_Load(sender As Object, e As EventArgs)
Dim panel As Panel = DirectCast(FormView1.FindControl("Panel1"), Panel)
Dim txt As RadTextBox = DirectCast(panel.FindControl("txtNombreEmpresa"), RadTextBox)
End Sub

Thanks,
Shinu.
0
Joan
Top achievements
Rank 1
answered on 12 Apr 2012, 08:16 AM
Oh.. i copied code from other .aspx , sorry!

<EditItemTemplate>
                    <uc1:ToolBarActualizar ID="toolbarAct1" runat="server" />                    
                      
                    <div id="TablaContenidos">
                        <div class="titulo">
                            <asp:Label ID="lblTitol" runat="server" CssClass="TitolsPanells" Text="Datos Usuario"></asp:Label>
                        </div>                        
                    </div>
  
                    <table id="DivPersones">
                           <tr>
                                <td class="style1" width="30%">
                                <td valign="top">
                                  <asp:Panel ID="panel1" runat="server" CssClass="auto-style2" style=" padding: 5px;  height: auto "   BorderStyle="Outset" BorderWidth="2px" BackColor="#EEEEEE"
                                           BorderColor="#CCCCCC" HorizontalAlign="Center"  >
  
                                        <table id="tblGrid" runat="server" visible="false" onclick="Return tbkGrid_onclick()">
                                            <tr>
                                                <td>
                                                    <telerik:RadGrid ID="RG1" runat="server" Skin="sunset" FilterMenu-BorderStyle="None" AllowFilteringByColumn="true" AllowSorting="true">
                                                    </telerik:RadGrid>
                                                </td>    
                                            </tr>
                                        </table>
                                          
                                        <fieldset>
                                            <legend>Datos usuario: </legend>
                                            <table class="auto-style1" runat="server" id="tbldatos" border="0" style="text-align: left" cellpadding="5">
                                                <tr>
                                                    <td><asp:Label ID="lblnom" runat="server" Text="Nombre: " /></td><td><telerik:RadTextBox ID="txtNom" CssClass="CampoCalculado" runat="server" text='<%#Bind ("Nombre") %>' ></telerik:RadTextBox></td>
                                                    <td><asp:Label ID="lblCognom" runat="server" Text="Apellidos: " ></asp:Label></td><td><telerik:RadTextBox ID="txtCnom" runat="server" CssClass="CampoNormal" text='<%#Bind ("Apellidos") %>'  ></telerik:RadTextBox></td>
                                                </tr>
                                                <tr>    
                                                    <td><asp:label id="lblCodi" runat="server" text="Codigo : "></asp:label></td><td><telerik:RadNumericTextBox ID="txtCodi" runat="server" CssClass="CampoCalculado"  NumberFormat-GroupSeparator="" NumberFormat-DecimalDigits="0"  text='<%#Bind ("Codigo_Usuario") %>' Enabled="false" ></telerik:RadNumericTextBox></td>
                                                    <td><asp:label ID="lblAdmin" runat="server" Text="Administrador: "></asp:label></td><td><asp:CheckBox id="txtAdmin" runat="server" Checked='<%#Bind ("Admin") %>' /></td>
                                                </tr>
                                                 
                                            </table>
                                        </fieldset
                                          
                                          
                                        <fieldset>
                                            <legend>Permisos: </legend>
  
  
                                            <telerik:RadGrid ID="RG2" runat="server" DataSourceID="sql" AllowPaging="true" ShowFooter="true"  
                                            ShowStatusBar="true" FilterMenu-EnableSelection="true" Width="500px" Height="200px" Skin="Telerik" AllowMultiRowSelection="false" >
                                              
                                                <ClientSettings>
                                                    <Scrolling AllowScroll="true"  UseStaticHeaders="true" />
                                                    <Selecting AllowRowSelect="true" /> 
                                                       
                                                </ClientSettings>
                                                <ValidationSettings CommandsToValidate="PefrormInsert, Update" EnableValidation="true" />
  
  
                                                <MasterTableView AutoGenerateColumns="false"  DataSourceID="sql" 
                                                  datakeynames="Codigo_Usuario" CanRetrieveAllData="true" HeaderStyle-HorizontalAlign="Center" >
                                               
                                                <Columns >
                                               
  
  
                                                   <telerik:GridTemplateColumn uniquename="Instalacio" AllowFiltering="true" HeaderText="Instalacion" datafield="Instalacion"  HeaderStyle-Width="120px" >
                                                            <ItemTemplate >
                                                                  <asp:SqlDataSource ID="sql1" runat="server" ConnectionString='<%$ ConnectionStrings:VisSecConnectionString1 %>'
                                                                                    SelectCommand="Select Instalacion,CodigoInstalacion from instalaciones where codigoinstalacion IN (select CodigoInstalacion from UsuariosPermisos)">
                                                                 </asp:SqlDataSource>
                                                                 <telerik:RadComboBox  ID="RCBnom" runat="server"  DataTextField="Instalacion" DataSourceID="sql1" Width="110px" 
                                                                  DataValueField="CodigoInstalacion"  CssClass="CampoCalculado" Enabled="true"  SelectedValue='<%#Eval ("CodigoInstalacion") %>'  ></telerik:RadComboBox>
                                                               
                                                           </ItemTemplate>
                                                   </telerik:GridTemplateColumn
                                                 <telerik:GridTemplateColumn UniqueName="Codi" AllowFiltering="false" HeaderText="Codigo Tabla" HeaderStyle-Width="100px"   >
                                                    <ItemTemplate>
                                                             <asp:SqlDataSource ID="sql6" runat="server" ConnectionString='<%$ ConnectionStrings:VisSecConnectionString1 %>' SelectCommand="select * from tablas where id_taula IN (select Codigotabla from usuariosPermisos)"    ></asp:SqlDataSource>
                                                             <telerik:RadComboBox ID="Ctaula" runat="server" Width="90px"  Enabled="true"  DataTextField="nom" DataValueField="id_taula" 
                                                             OnDataBinding="tau" DataSourceID="sql6" selectedValue='<%#Eval ("Codigotabla") %>'>
  
                                                             </telerik:RadComboBox>
                                                              
                                                   </ItemTemplate>
                                                   </telerik:GridTemplateColumn>
                                                             
                                                                                  
                                                   
                                                      
  
                                                   <telerik:GridTemplateColumn HeaderText="Consultar" DataField="Consultar" UniqueName="Consultar" >
                                                     
                                                                <ItemTemplate>
                                                                    <asp:CheckBox  ID="Consultar" runat="server"   Checked='<%# Bind("Consultar") %>' OnCheckedChanged="upt"></asp:CheckBox>
                                                                      
                                                                </ItemTemplate>  
                                                               
                                                                  
                                                                  
                                                   </telerik:GridTemplateColumn>
                                                      
                                                    <telerik:GridTemplateColumn UniqueName="Afegir" AllowFiltering="true" HeaderText="Añadir" >
                                                            <ItemTemplate >
                                                                
                                                                                 <asp:CheckBox  ID="Anadir" runat="server"  Checked='<%# Bind("Anadir") %>'   OnCheckedChanged='upt' ></asp:CheckBox>
                                                           </ItemTemplate>
                                                   </telerik:GridTemplateColumn>
                                                    <telerik:GridTemplateColumn UniqueName="Modificar" AllowFiltering="true" HeaderText="Modificar" >
                                                        <ItemTemplate>
                                                              
                                                                                 <asp:CheckBox  ID="Modificar" runat="server"  Checked='<%# Bind("Modificar") %>'  OnCheckedChanged="upt" ></asp:CheckBox>
                                                        </ItemTemplate>
  
                                                   </telerik:GridTemplateColumn>
                                                    <telerik:GridTemplateColumn UniqueName="Esborrar" AllowFiltering="true" HeaderText="Borrar" >
                                                            <ItemTemplate>
                                                                  
                                                                                 <asp:CheckBox  ID="Borrar" runat="server"  Checked='<%# Bind("Borrar") %>'  OnCheckedChanged="upt" ></asp:CheckBox>
                                                            </ItemTemplate>
                                                   </telerik:GridTemplateColumn
                                                  
                                                      
                                                 </Columns>
                                                  
                                                </MasterTableView>
  
                                                </telerik:RadGrid
                                                                                               
                                                  
                                        </fieldset>                                      
                                    </asp:Panel>
                                    
                                  </td>
                             </tr>
                       </table>
                 
               </EditItemTemplate>


this is the code where i have the problem described, sorry again for copy another thing :(

Thanks a lot.
0
Accepted
Shinu
Top achievements
Rank 2
answered on 12 Apr 2012, 11:02 AM
Hello Joan,

Try the following code.
VB:
Protected Sub Page_Load(sender As Object, e As EventArgs)
    Dim panel As Panel = DirectCast(FormView1.FindControl("panel1"), Panel)
       Dim grid1 As RadGrid = DirectCast(panel.FindControl("RG1"), RadGrid)
    Dim grid2 As RadGrid = DirectCast(panel.FindControl("RG2"), RadGrid)
End Sub

Thanks,
Shinu.
0
Joan
Top achievements
Rank 1
answered on 12 Apr 2012, 11:31 AM
It Works!!!1

thank you very very very  much!!!!

i apologize for all problems i gave to you.

Thanks again, you rock Shinu.
Tags
Grid
Asked by
Joan
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Joan
Top achievements
Rank 1
Share this question
or