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

rebinding data grid

1 Answer 30 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Webster Velasco
Top achievements
Rank 2
Webster Velasco asked on 01 Mar 2010, 04:54 PM
hi

i have a problem on rebinding my 2nd datagrid..

here what i really want.. i want to rebind my "grdOrdini" on click at "grdListini -> btnAdd" but it doesnt work.. i tried anything looking to any demos available on your site

here is the code:

html:
<%@ Page Language="vb" MasterPageFile="~/Main.Master" AutoEventWireup="false" CodeBehind="ElencoOrdini.aspx.vb" Inherits="GRC30.ElencoOrdini" %> 
 
<asp:Content ID="congrcElencoOrdini" ContentPlaceHolderID="cphMain" Runat="Server"
    <div style="height:100%"
        <!-- inizio contenuto --> 
        <!-- content start --> 
        <telerik:RadAjaxManager ID="RadAjaxManager2" runat="server"
            <AjaxSettings> 
                <telerik:AjaxSetting AjaxControlID="grdListini"
                    <UpdatedControls> 
                        <telerik:AjaxUpdatedControl ControlID="grdListini" /> 
                    </UpdatedControls> 
                </telerik:AjaxSetting>   
                <telerik:AjaxSetting AjaxControlID="grdOrdini"
                    <UpdatedControls> 
                        <telerik:AjaxUpdatedControl ControlID="grdOrdini" /> 
                    </UpdatedControls> 
                </telerik:AjaxSetting>                               
            </AjaxSettings> 
        </telerik:RadAjaxManager> 
        <table width="100%" align="center" border="0"
            <tr> 
                <th align="center" class="tbContorno"><asp:Label runat="server" ID="lblTitolo" Text="Elenco Servizi Offerti" />  
                </th> 
            </tr> 
            <tr> 
                <td>         
                    <telerik:RadGrid ID="grdListini" DataSourceID="objDS" runat="server" Width="99.7%" 
                        AutoGenerateColumns="False" PageSize="10" AllowSorting="True" AllowPaging="True" 
                        GridLines="None" ShowStatusBar="true"
                        <PagerStyle Mode="NumericPages"></PagerStyle> 
                        <MasterTableView DataSourceID="objDS" DataKeyNames="CODICE" AllowMultiColumnSorting="True" 
                            Width="100%"
                            <Columns> 
                                <telerik:GridTemplateColumn> 
                                    <ItemTemplate> 
                                        <asp:ImageButton runat="server" ID="BtnAdd" OnClick="btnAddclick" ImageUrl="~/img/addCart.png" ToolTip="Aggiungi nell'elenco ordine" /> 
                                    </ItemTemplate> 
                                </telerik:GridTemplateColumn> 
                                <telerik:GridBoundColumn SortExpression="CODICE" HeaderText="Codice" DataField="CODICE" UniqueName="colCODICE" Visible="false"
                                </telerik:GridBoundColumn>                 
                                <telerik:GridBoundColumn SortExpression="DESCRIZIONE" HeaderText="Descrizione" DataField="DESCRIZIONE" UniqueName="colDESCRIZIONE"
                                </telerik:GridBoundColumn> 
                                <telerik:GridBoundColumn SortExpression="COSTO" HeaderText="Prezzo" DataField="COSTO" UniqueName="colCOSTO"
                                </telerik:GridBoundColumn> 
                                <telerik:GridDateTimeColumn SortExpression="DTDA" HeaderText="Valido dal" DataField="DTDA" UniqueName="colDTDA"
                                </telerik:GridDateTimeColumn> 
                                <telerik:GridDateTimeColumn SortExpression="DTA" HeaderText="Valido al" DataField="DTA" UniqueName="colDTA"
                                </telerik:GridDateTimeColumn> 
                                <telerik:GridBoundColumn SortExpression="DURATA" HeaderText="Durata" DataField="DURATA" UniqueName="colDURATA"
                                </telerik:GridBoundColumn>                                         
                            </Columns> 
                        </MasterTableView> 
                    </telerik:RadGrid>    
                </td> 
            </tr> 
            <tr> 
                <td style="height:10px">&nbsp;</td> 
            </tr> 
            <tr> 
                <th align="center" class="tbContorno"><asp:Label runat="server" ID="Label1" Text="Elenco Ordini" />  
                </th> 
            </tr> 
            <tr> 
                <td>         
                    <telerik:RadGrid ID="grdOrdini" DataSourceID="objDSOrd" runat="server" Width="99.7%" 
                        AutoGenerateColumns="False" PageSize="15" AllowSorting="True" AllowPaging="True" 
                        GridLines="None" ShowStatusBar="true" AllowAutomaticUpdates="true" EnableViewState="false"
                        <PagerStyle Mode="NumericPages"></PagerStyle> 
                        <MasterTableView DataSourceID="objDSOrd" DataKeyNames="CODICE" AllowMultiColumnSorting="True" 
                            Width="100%"
                            <Columns> 
                                <telerik:GridButtonColumn ConfirmText="Rimouvere dal Elenco degli ordini?" ButtonType="ImageButton" ImageUrl="~/img/DelCart.png" CommandName="Delete" Text="Rimouvi dal elenco" UniqueName="colDelete"
                                    <HeaderStyle Width="35px" /> 
                                </telerik:GridButtonColumn>                              
                                <telerik:GridEditCommandColumn EditImageUrl="~/img/Edit.gif" UniqueName="btnEdit" CancelText="Cancel" UpdateText="Save" EditText="Modifica"></telerik:GridEditCommandColumn>                           
                                <telerik:GridBoundColumn SortExpression="LISTINO" HeaderText="Listino" DataField="LISTINO" UniqueName="colLISTINO" ReadOnly="true"
                                </telerik:GridBoundColumn>                 
                                <telerik:GridBoundColumn SortExpression="DTORDINE" HeaderText="Data Ordine" DataField="DTORDINE" UniqueName="colDTORDINE" DataType="System.DateTime" DataFormatString="{0: dd/MM/yyyy}" ReadOnly="true"
                                </telerik:GridBoundColumn> 
                                <telerik:GridBoundColumn SortExpression="DTSCADENZA" HeaderText="Data Scadenza" DataField="DTSCADENZA" UniqueName="colDTSCADENZA" DataType="System.DateTime" DataFormatString="{0: dd/MM/yyyy}" ReadOnly="true"
                                </telerik:GridBoundColumn> 
                                <telerik:GridNumericColumn SortExpression="QUANTITA" HeaderText="Q.tà" DataField="QUANTITA" UniqueName="colQUANTITA"
                                </telerik:GridNumericColumn> 
                                <telerik:GridNumericColumn SortExpression="COSTOUNITARIO" HeaderText="Costo Unitario" DataField="COSTOUNITARIO" UniqueName="colCOSTOUNITARIO" DataType="System.Double" DataFormatString="{0:€ # ###.##}" ReadOnly="true"
                                </telerik:GridNumericColumn> 
                                <telerik:GridNumericColumn SortExpression="SCONTO" HeaderText="Sconto %" DataField="SCONTO" UniqueName="colSCONTO" ReadOnly="true" DataType="System.Double" DataFormatString="{0: ###.##%}"
                                </telerik:GridNumericColumn> 
                                <telerik:GridNumericColumn SortExpression="COSTONETTO" HeaderText="Costo Netto" DataField="COSTONETTO" UniqueName="colCOSTONETTO" NumericType="Currency" DataType="System.Double" DataFormatString="{0:€ # ###.##}" ReadOnly="true"
                                </telerik:GridNumericColumn>                                         
                            </Columns> 
                        </MasterTableView> 
                    </telerik:RadGrid>    
                </td> 
            </tr>             
            <tr> 
                <asp:Label ID="lblErrorMsg" runat="server" /> 
            </tr> 
        </table>                       
        <!-- fine --> 
    <asp:ObjectDataSource  
        ID="objDS"  
        runat="server"  
        SelectMethod="SelectListino" 
        SortParameterName="orderBy"      
        TypeName="GestioneElenco" > 
        <SelectParameters>  
            <asp:ControlParameter ControlID="grdListini" Name="filterBy" PropertyName="MasterTableView.FilterExpression" Type="String" />  
            <asp:Parameter Name="NomeSP" DefaultValue="Web2k5_CommittenteListiniElenco" Type="String" /> 
            <asp:Parameter Name="committ" Type="int32" /> 
        </SelectParameters>  
    </asp:ObjectDataSource> 
     
    <asp:ObjectDataSource  
        ID="objDSOrd"  
        runat="server"  
        SelectMethod="SelectListino" 
        SortParameterName="orderBy"      
        TypeName="GestioneElenco" > 
        <SelectParameters>  
            <asp:ControlParameter ControlID="grdOrdini" Name="filterBy" PropertyName="MasterTableView.FilterExpression" Type="String" />  
            <asp:Parameter Name="NomeSP" DefaultValue="Web2k5_CommittenteOrdiniElenco" Type="String" /> 
            <asp:Parameter Name="committ" Type="int32" /> 
        </SelectParameters>  
    </asp:ObjectDataSource> 
 
    </div> 
</asp:Content> 
 

code behind:
Imports Telerik.Web.UI 
Partial Public Class ElencoOrdini 
    Inherits System.Web.UI.Page 
 
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 
        If Not IsPostBack Then 
            'reset the states 
            'Me.Session(_gridState.SessionKey) = _gridState 
            If Session("grcCodice") <> Nothing Then 
                objDS.SelectParameters("committ").DefaultValue = Session("grcCodice") 
                objDSOrd.SelectParameters("committ").DefaultValue = Session("grcCodice") 
            Else 
                Response.Redirect("Login.aspx?action=Scad") 
            End If 
        End If 
    End Sub 
 
    Protected Sub btnAddclick(ByVal sender As Object, ByVal e As ImageClickEventArgs) 
        Dim btn As ImageButton = sender 
 
        ReDim param(1) 
        ReDim paramVal(1) 
 
        param(0) = "COMMITTENTE" 
        If Session("grcCodice") <> Nothing Then 
            paramVal(0) = Session("grcCodice") 
        Else 
            Response.Redirect("Login.aspx?action=Scad") 
        End If 
 
        param(1) = "LISTINO" 
        paramVal(1) = btn.CommandArgument 
 
        ApriConnessioni() 
        EseguiStored("Web2k5_CommittentiOrdiniInsert", param, paramVal, kAggiornaDati, True) 
        If TestoMessaggio.Length > 0 Then 
            lblErrorMsg.Text = TestoMessaggio 
            ChiudiConnessioni() 
            Exit Sub 
        End If 
        ChiudiConnessioni() 
 
        RadAjaxManager2.RaisePostBackEvent("rebind") 
    End Sub 
 
    Protected Sub RadAjaxManager1_AjaxRequest(ByVal sender As Object, ByVal e As Telerik.Web.UI.AjaxRequestEventArgs) Handles RadAjaxManager2.AjaxRequest 
        grdOrdini.Rebind() 
        grdOrdini.MasterTableView.Rebind() 
    End Sub 
    Protected Sub grdListini_ItemCreated(ByVal sender As Object, ByVal e As GridItemEventArgs) Handles grdListini.ItemCreated 
        Try 
            If TypeOf e.Item Is GridDataItem Then 
                Dim BtnAdd As ImageButton = DirectCast(e.Item.FindControl("BtnAdd"), ImageButton) 
                Dim idCA As String = DirectCast(e.Item.OwnerTableView.DataKeyValues(e.Item.ItemIndex)("CODICE"), String) 
                BtnAdd.CommandArgument = idCA 
            End If 
        Catch ex As Exception 
            SentMessage("Error ItemCreated: " & ex.Message) 
        End Try 
    End Sub 
 
    Private Sub DisplayMessage(ByVal text As String, ByVal grd As RadGrid) 
        grd.Controls.Add(New LiteralControl(String.Format("<span style='color:red'>{0}</span>", "<br />" & text))) 
    End Sub 
 
    Private gridMessage As String = Nothing 
    Protected Sub grdPap_DataBound(ByVal sender As Object, ByVal e As EventArgs) Handles grdListini.DataBound 
        If Not String.IsNullOrEmpty(gridMessage) Then 
            DisplayMessage(gridMessage, grdListini) 
        End If 
    End Sub 
 
    Private Sub SentMessage(ByVal text As String) 
        gridMessage = text 
    End Sub 
 
End Class 







1 Answer, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 1
answered on 02 Mar 2010, 09:54 AM
Hi,

You need to modify your Ajax Settings. Inorder for the grid  grdListini to update grdOrdini you need to have the Ajax setting as  shown below:

ASPX:
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server"
            <ajaxsettings> 
                <telerik:AjaxSetting AjaxControlID="grdListni"
                    <UpdatedControls> 
                        <telerik:AjaxUpdatedControl ControlID="grdListini" /> 
                        <telerik:AjaxUpdatedControl ControlID="grdOrdini" /> 
                      
                    </UpdatedControls> 
                </telerik:AjaxSetting> 

For more info refer to the demo link below:

Hope this helps.

Thanks,
Princy
Tags
Grid
Asked by
Webster Velasco
Top achievements
Rank 2
Answers by
Princy
Top achievements
Rank 1
Share this question
or