By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,190 Members | 765 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,190 IT Pros & Developers. It's quick & easy.

Accessing Datagrid properties within a user control from the outside

P: n/a
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
Nov 18 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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...F720AB013.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

Nov 18 '05 #2

P: n/a
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" <he************@CAPS.AND.DOTS.hotmail.com> wrote in message
news:C6**********************************@microsof t.com...
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...F720AB013.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

Nov 18 '05 #3

P: n/a
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" <cr**********@yarrasoftware.com> wrote in message
news:%2******************@TK2MSFTNGP15.phx.gbl...
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" <he************@CAPS.AND.DOTS.hotmail.com> wrote in message
news:C6**********************************@microsof t.com...
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...F720AB013.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


Nov 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.