Accessing Datagrid properties within a user control from the outside

Discussion in 'ASP .Net' started by Craig G, Nov 30, 2004.

  1. Craig G

    Craig G Guest

    i have a user control which is basically a datagrid, which has
    add/edit/delete buttons on the grid

    is there anyway of accessing the actual datagrid from the form itself?

    basically i want to set the add/edit/delete options visble/invisible on the
    datagrid depending on the users's role, but found that i cannot access the
    grid to do this.

    is the only way of setting it in the page load of the usercontrol itself?

    Cheers,
    Craig
     
    Craig G, Nov 30, 2004
    #1
    1. Advertising

  2. RE: Accessing Datagrid properties within a user control from the outsi

    Craig,

    You can define method and properties for your user control exposing whatever
    you wish to with the desired scope.

    ie have a public property say Button1Visible which internally sets the value
    of the button 1 of your user control... have a look the link below to see how
    you can access method and properties of user control from within aspx page

    http://www.dotnetjunkies.com/Article/E1F97CE9-7834-46FA-BED9-866F720AB013.dcik

    "Craig G" wrote:

    > i have a user control which is basically a datagrid, which has
    > add/edit/delete buttons on the grid
    >
    > is there anyway of accessing the actual datagrid from the form itself?
    >
    > basically i want to set the add/edit/delete options visble/invisible on the
    > datagrid depending on the users's role, but found that i cannot access the
    > grid to do this.
    >
    > is the only way of setting it in the page load of the usercontrol itself?
    >
    > Cheers,
    > Craig
    >
    >
    >
     
    =?Utf-8?B?SGVybWl0IERhdmU=?=, Nov 30, 2004
    #2
    1. Advertising

  3. Craig G

    Craig G Guest

    Re: Accessing Datagrid properties within a user control from the outsi

    cheers for that.

    so in the user control its just a case of saying something like this?

    Public Property SetDelete()

    Get
    return DataGrid1.Columns(0).Visible
    End Get

    Set(ByVal Value)
    DataGrid1.Columns(0).Visible = Value
    End Set

    End Property

    then in the code behind of the page, something like this?


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles Button1.Click

    Dim myUC As New WebUserControl2
    myUC.SetDelete = False
    End Sub


    when i do this i get an error in the ascx saying objectReference not set to
    an instance of an obejct, and it is falling over in the following line

    DataGrid1.Columns(0).Visible = Value

    Cheers,
    Craig




    "Hermit Dave" <> wrote in message
    news:...
    > Craig,
    >
    > You can define method and properties for your user control exposing

    whatever
    > you wish to with the desired scope.
    >
    > ie have a public property say Button1Visible which internally sets the

    value
    > of the button 1 of your user control... have a look the link below to see

    how
    > you can access method and properties of user control from within aspx page
    >
    >

    http://www.dotnetjunkies.com/Article/E1F97CE9-7834-46FA-BED9-866F720AB013.dcik
    >
    > "Craig G" wrote:
    >
    > > i have a user control which is basically a datagrid, which has
    > > add/edit/delete buttons on the grid
    > >
    > > is there anyway of accessing the actual datagrid from the form itself?
    > >
    > > basically i want to set the add/edit/delete options visble/invisible on

    the
    > > datagrid depending on the users's role, but found that i cannot access

    the
    > > grid to do this.
    > >
    > > is the only way of setting it in the page load of the usercontrol

    itself?
    > >
    > > Cheers,
    > > Craig
    > >
    > >
    > >
     
    Craig G, Nov 30, 2004
    #3
  4. Craig G

    Craig G Guest

    Re: Accessing Datagrid properties within a user control from the outsi

    sorry...my fault

    didnt realise when you declare the object in the code behind that it must
    use the same ID as the usercontrol on the screen

    "Craig G" <> wrote in message
    news:%23Ax8%...
    > cheers for that.
    >
    > so in the user control its just a case of saying something like this?
    >
    > Public Property SetDelete()
    >
    > Get
    > return DataGrid1.Columns(0).Visible
    > End Get
    >
    > Set(ByVal Value)
    > DataGrid1.Columns(0).Visible = Value
    > End Set
    >
    > End Property
    >
    > then in the code behind of the page, something like this?
    >
    >
    > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
    > System.EventArgs) Handles Button1.Click
    >
    > Dim myUC As New WebUserControl2
    > myUC.SetDelete = False
    > End Sub
    >
    >
    > when i do this i get an error in the ascx saying objectReference not set

    to
    > an instance of an obejct, and it is falling over in the following line
    >
    > DataGrid1.Columns(0).Visible = Value
    >
    > Cheers,
    > Craig
    >
    >
    >
    >
    > "Hermit Dave" <> wrote in message
    > news:...
    > > Craig,
    > >
    > > You can define method and properties for your user control exposing

    > whatever
    > > you wish to with the desired scope.
    > >
    > > ie have a public property say Button1Visible which internally sets the

    > value
    > > of the button 1 of your user control... have a look the link below to

    see
    > how
    > > you can access method and properties of user control from within aspx

    page
    > >
    > >

    >

    http://www.dotnetjunkies.com/Article/E1F97CE9-7834-46FA-BED9-866F720AB013.dcik
    > >
    > > "Craig G" wrote:
    > >
    > > > i have a user control which is basically a datagrid, which has
    > > > add/edit/delete buttons on the grid
    > > >
    > > > is there anyway of accessing the actual datagrid from the form itself?
    > > >
    > > > basically i want to set the add/edit/delete options visble/invisible

    on
    > the
    > > > datagrid depending on the users's role, but found that i cannot access

    > the
    > > > grid to do this.
    > > >
    > > > is the only way of setting it in the page load of the usercontrol

    > itself?
    > > >
    > > > Cheers,
    > > > Craig
    > > >
    > > >
    > > >

    >
    >
     
    Craig G, Nov 30, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Roy
    Replies:
    1
    Views:
    888
    Scott Allen
    Feb 10, 2005
  2. Mad Scientist Jr
    Replies:
    0
    Views:
    674
    Mad Scientist Jr
    Mar 22, 2006
  3. tshad
    Replies:
    3
    Views:
    590
    tshad
    May 19, 2006
  4. Max2006
    Replies:
    2
    Views:
    536
    Max2006
    Jul 13, 2007
  5. Krzysztof Poc

    outside type, outside function

    Krzysztof Poc, Feb 3, 2012, in forum: C++
    Replies:
    1
    Views:
    314
    Victor Bazarov
    Feb 7, 2012
Loading...

Share This Page