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

Empty Datasource on Insert/Update Command at serverside

1 Answer 109 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
sunitha asked on 29 Sep 2008, 09:38 PM
I'm having issues with Databinding and finding item controls in my DataGrid.
I'm using Radcontrols for ASP.NET Ajax Q2 2008.
Here's what I have.

1.I have a grid that I load in edit mode with NeedDS databinding.
2.It has a GridClientSelectColumn for selecting multiple editable rows.
3.On click of CommandItemTemplate button, the selected items are to be retrieved on server side for update/insert.
4.I also have to Insert a record with Add New Record command item template.

I have 1 and 2 working.
3 and 4 dont work since the datagrid.datasource becomes nothing in update_command and Insert_command events.  How do I retrieve the edited data?

Please help!
Heres my code.

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="GridTrial._Default" %> 
<%@ Register  TagPrefix="telerik" Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" %> 
<%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" 
    Namespace="System.Web.UI" TagPrefix="asp" %> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ""> 
<html xmlns="" > 
<head runat="server">  
    <title>Untitled Page</title> 
    <form id="form1" runat="server">  
    <asp:ScriptManager ID="ScriptManager1" runat="server" AsyncPostBackTimeout ="3600000"></asp:ScriptManager> 
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">  
                <telerik:AjaxSetting AjaxControlID="RADGResults">  
                        <telerik:AjaxUpdatedControl ControlID="RADGResults" /> 
        <telerik:RadGrid ID="RADGResults" MasterTableView-Width="100%" runat="server" Skin="NCCI"   
             AllowSorting="false" EnableEmbeddedSkins="false" AllowMultiRowSelection="true"   
             AllowMultiRowEdit="true" AutoGenerateColumns="false"   
             GridLines="None" > 
                <Selecting AllowRowSelect="True"  EnableDragToSelectRows="false"/>  
                <Scrolling  AllowScroll="True" /> 
            <SelectedItemStyle  BackColor="gray"    /> 
            <MasterTableView EditMode="InPlace"  CommandItemDisplay="top"       > 
            <ItemStyle CssClass="MainTableEvenColumnCorp"/>  
            <HeaderStyle CssClass="ms-formlabel MainTableHeaderCORP" Font-Size="x-Small"></HeaderStyle> 
            <AlternatingitemStyle CssClass="MainTableOddColumnCorp"/>  
                <telerik:GridClientSelectColumn UniqueName="ClientSelectColumn"  ItemStyle-ForeColor="beige"/>                   
                <telerik:GridTemplateColumn HeaderText="Report Number"  UniqueName="ReportNumber">  
                    <ItemStyle HorizontalAlign="Center"    /> 
                    <HeaderStyle HorizontalAlign="Center"    /> 
                        <asp:Label id="txtReport" runat="server" Text='<%# DataBinder.Eval(Container,"DataItem.Report_Number") %>'></asp:Label> 
                        <asp:Label id="txtReport" runat="server" Text='<%# DataBinder.Eval(Container,"DataItem.Report_Number") %>'></asp:Label> 
                       <asp:DropDownList id="ddlReport" runat="server" DataTextField="Report_Number" visible="false"  > 
                            <asp:ListItem Value='1' ></asp:ListItem> 
                            <asp:ListItem Value='2' ></asp:ListItem> 
                            <asp:ListItem Value='3' ></asp:ListItem> 
                            <asp:ListItem Value='4' ></asp:ListItem> 
                            <asp:ListItem Value='5' ></asp:ListItem> 
               <telerik:GridBoundColumn DataField ="Number Of Risks" HeaderText ="Number Of Risks" UniqueName="NumberOfRisks"   > 
                    <ItemStyle HorizontalAlign="Center"    /> 
                    <HeaderStyle HorizontalAlign="Center"    /> 
           </Columns >             
    <CommandItemStyle HorizontalAlign="Center" /> 
         <asp:LinkButton ID="btnUpdateEdited" runat="server" CommandName="UpdateEdited"  Visible='<%# RADGResults.EditIndexes.Count > 0 %>'><img style="border:0px" alt="" src="../media/Update.gif" /> Update Customers</asp:LinkButton> 
        <asp:LinkButton ID="btnCancel" runat="server" CommandName="CancelAll" Visible='<%# RADGResults.EditIndexes.Count > 0 or RADGResults.MasterTableView.IsItemInserted %>'><img style="border:0px" alt="" src="../media/Cancel.gif" /> Cancel editing</asp:LinkButton> 
         <asp:LinkButton ID="LinkButton2" runat="server" CommandName="InitInsert" Visible='<%# not RADGResults.MasterTableView.IsItemInserted %>'><img style="border:0px" alt="" src="../media/AddRecord.gif" /> Add new Customer</asp:LinkButton> 
         <asp:LinkButton ID="LinkButton3" runat="server" CommandName="PerformInsert" Visible='<%# RADGResults.MasterTableView.IsItemInserted %>'><img style="border:0px" alt="" src="../media/AddRecord.gif" /> Add this Customer</asp:LinkButton> 
        <asp:LinkButton ID="LinkButton1" OnClientClick="javascript:return confirm('Delete all selected customers?')" 
            runat"server" CommandName="DeleteSelected"><img style="border:0px" alt="" src="../media/Delete.gif" /> Delete Selected Customers</asp:LinkButton> 
        <asp:LinkButton ID="LinkButton4" runat="server" CommandName="Re bindGrid"><img style="border:0px" alt="" src="../media/Refresh.gif" /> Refresh customer list</asp:LinkButton> 
In the code behind  
Partial Public Class _Default  
    Inherits System.Web.UI.Page  
    Public DBGrid As New GridBind  
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load  
        '  changes grid into inline edit mode without rebind  
        Dim i As Integer  
        For i = 0 To RADGResults.PageSize - 1  
        Next i  
    End Sub  
    Private Sub RADGResults_NeedDataSource(ByVal source As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles RADGResults.NeedDataSource  
       RADGResults.DataSource = Me.GridSource 
    End Sub  
 Private ReadOnly Property GridSource() As DataTable

Dim obj As Object = Me.ViewState("_gds")
If (Not obj Is Nothing) Then
Return CType(obj, DataTable)


Dim table As New DataTable()
table = loadgrid()
Me.ViewState("_gds") = table
Return table
End If

End Get
End Property

Protected Function loadgrid() As DataTable

Dim dt As New DataTable
ds = CrotablemaintPkgDAO.getExposureSummary.createRequest(FilingControl.StateCode, FilingControl.FilingID, txtClassCd.Text, "curExp").execute
If ds.Tables(0).Rows.Count > 0 Then
dt = ds.Tables(0)
end if
end function

    Private Sub RADGResults_UpdateCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RADGResults.UpdateCommand  
        'gridclientselectcolumn selected for multiple updates  
        For Each dataitem As Telerik.Web.UI.GridEditableItem In RADGResults.SelectedItems  
            '  For Each dataitem As Telerik.Web.UI.GridDataItem In RADGResults.MasterTableView.Items  
            '   For Each dataitem As Telerik.Web.UI.GridEditableItem In RADGResults.MasterTableView.Items   'even tried Editable Item  
            Dim strsql As String  
            'the grid.datasource is now nothing  
            strsql = dataitem("Report_Number").Text 'cannot retrieve any edittemplate/itemtemplate/boundcolumn values  
    End Sub  
    Private Sub RADGResults_InsertCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RADGResults.InsertCommand  
        Dim insertedItem As Telerik.Web.UI.GridEditFormInsertItem = DirectCast(e.Item, Telerik.Web.UI.GridEditFormInsertItem)  
        'the grid.datasource is now nothing  
        Dim risk As String = (TryCast(insertedItem("Report_Number").Controls(0), TextBox)).Text     'cannot retrieve the inserted edittemplate/itemtemplate/boundcolumn values  
    End Sub  
End Class  

1 Answer, 1 is accepted

Sort by
Telerik team
answered on 02 Oct 2008, 10:56 AM
Hi sunitha ,

To see more information along the lines of the requested functionality, please refer to the following sample, which handles a similar task. I hope it gets you started properly.

Kind regards,
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Asked by
Top achievements
Rank 1
Answers by
Telerik team
Share this question