Find radupload in radgrid

Thread is closed for posting
3 posts, 0 answers
  1. Neri
    Neri avatar
    3 posts
    Member since:
    Aug 2012

    Posted 22 Aug 2012 Link to this post

    Hello, excuse me for my English I am French ...
    I try to call in my code the RadUpload control with ID = radupload1

    I tried several methods to find the RadUpload control example:
     

    Dim RadUpload1 As RadUpload = CType(MyUserControl.FindControl("RadUpload1"), RadUpload)

     
    but I get the error message:
    Object reference not set to an instance of an object.
    Description: An unhandled exception occurred during the execution of the current web request. Check the stack trace for more information about the error and where it originated in the code.
    Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.


    1. here is my code aspx
    :

    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default2.aspx.vb" Inherits="admin_Default2" %>

    <%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml">

    <head runat="server">

        <title></title>

    </head>

    <body>

        <form id="form1" runat="server">

        <div>

        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">

     

    <ajaxsettings>

    <telerik:AjaxSetting AjaxControlID="RadGrid1">

    <updatedcontrols>

    <telerik:AjaxUpdatedControl ControlID="RadGrid1" />

     

    </updatedcontrols>

    </telerik:AjaxSetting>

    </ajaxsettings>

     

     

    </telerik:RadAjaxManager>

     

            <telerik:RadScriptManager ID="RadScriptManager1" runat="server">

            </telerik:RadScriptManager>

        <telerik:RadGrid ID="RadGrid1" runat="server" GridLines="None" AutoGenerateColumns="false"  DataSourceID="SqlDataSource1" AutoGenerateEditColumn="true" >

     

        <MasterTableView Width="100%" DataKeyNames="idActualite" CommandItemDisplay="Top"

     

            EditMode="PopUp">

     

            <Columns>

     

               <telerik:GridTemplateColumn>

     

                    <HeaderTemplate>

     

                        <asp:TextBox ID="txtCodeNumber" runat="server" Width="39px" />

     

                       <asp:LinkButton ID="lnkAddCode" runat="server" Text="Add Bulk Code" OnClick="lnkAddCode_Click" />

     

                    </HeaderTemplate>

     

                    <ItemTemplate>

     

                        <asp:TextBox ID="TextBox1" runat="server" Text='<%#Bind("titre") %>' Width="39px" />

     

                    </ItemTemplate>

                      <EditItemTemplate>

                            

                             <telerik:RadUpload ID="RadUpload1" runat="server"   AllowedFileExtensions=".jpg,.jpeg" Skin="Black"></telerik:RadUpload>

                             <telerik:RadProgressArea ID="RadProgressArea1" runat="server"></telerik:RadProgressArea>

                           

                               

                            </EditItemTemplate>

     

                </telerik:GridTemplateColumn>

     

            </Columns>

     

        </MasterTableView>

     

    </telerik:RadGrid>

      <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnGestion %>"

            SelectCommand="SELECT * FROM [actualites] ORDER BY idActualite DESC" InsertCommand="INSERT INTO [actualites] ([titre], [descriptif], [dataImage]) VALUES (@titre, @descriptif, @dataImage) SET @InsertedID = SCOPE_IDENTITY()"

            UpdateCommand="UPDATE [actualites] SET [titre] = @titre, [descriptif] = @descriptif, [dataImage] = @dataImage WHERE [idActualite] = @idActualite"

            DeleteCommand="DELETE FROM [actualites] WHERE [idActualite] = @idActualite"

            >

            <InsertParameters>

                <asp:Parameter Name="titre" Type="String" />

                <asp:Parameter Name="descriptif" Type="String" />

                <asp:Parameter Name="dataImage" DbType="Binary" />

                <asp:Parameter Name="InsertedID" Type="Int32" Direction="Output" />

            </InsertParameters>

            <UpdateParameters>

                <asp:Parameter Name="titre" Type="String" />

                <asp:Parameter Name="descriptif" Type="String" />

                <asp:Parameter Name="idActualite" Type="Int32" />

                <asp:Parameter Name="dataImage" DbType="Binary" />

            </UpdateParameters>

            <DeleteParameters>

                <asp:Parameter Name="idActualite" Type="Int32" />

            </DeleteParameters>

        </asp:SqlDataSource>

         

        </div>

        </form>

    </body>

    </html>

    2. here is my code aspx.vb:

    Imports System

    Imports System.Drawing

    Imports System.Data

    Imports System.Configuration

    Imports System.Web

    Imports System.Web.Security

    Imports System.Web.UI

    'Imports System.Web.UI.WebControls

    Imports System.Web.UI.WebControls.WebParts

    Imports System.Web.UI.HtmlControls

    Imports System.Data.SqlClient

    Imports System.Data.SqlTypes

    Imports System.IO

    Imports System.Collections.Generic

    Imports System.Collections

    Imports System.ComponentModel

    Imports System.Web.SessionState

    Imports Telerik.Web.UI

    Partial Class admin_Default2

        Inherits System.Web.UI.Page

        Public txtCodeNumber As RadUpload

        Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load

        

        End Sub

        Protected Sub RadGrid1_InsertCommand(sender As Object, e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.InsertCommand

           

            Dim MyUserControl As UserControl = CType(e.Item.FindControl(GridEditFormItem.EditFormUserControlID), UserControl)

            Dim RadUpload1 As RadUpload = CType(MyUserControl.FindControl("RadUpload1"), RadUpload)

        End Sub

    End Class

    Thanks for your help,

  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 23 Aug 2012 Link to this post

    Hi,

    Try the following code to access RadUpload in grid.
    VB:
    Protected Sub RadGrid1_InsertCommand(sender As Object, e As GridCommandEventArgs)
        Dim item As GridEditFormInsertItem = DirectCast(e.Item, GridEditFormInsertItem)
        Dim up As RadUpload = DirectCast(item.FindControl("RadUpload1"), RadUpload)
    End Sub

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Neri
    Neri avatar
    3 posts
    Member since:
    Aug 2012

    Posted 23 Aug 2012 Link to this post


    thank you for your answer, it works
Back to Top