Solved

user control properties in datagrid

Posted on 2004-08-10
11
439 Views
Last Modified: 2012-06-21
hi all

 i have user control which is populates with in datagrid

<asp:datagrid id="DataGrid1" runat="server">
<Columns>                                                      <ItemTemplate>
<usercontrol:My id="UC" runat="server"/>
      </ItemTemplate>
<Columns>
</asp:datagrid>

the user control has properties like


 Public Property empID() As Integer
        Get
            Return ID
        End Get
        Set(ByVal Value As Integer)

            ID = Value

        End Set
    End Property


how to dynamically get and set the properties of usercontrol?????????????????

i tried  method findcontrol() with in DataGrid ItemDataBound method but it doest working

please help me


0
Comment
Question by:Basic
  • 6
  • 4
11 Comments
 
LVL 28

Expert Comment

by:mmarinov
ID: 11764602
Hi,

yes, the correct solution for your scenario is by using FindControl method like this in the ItemDataBound event

if  e.Item.ItemType = ListItem.Item Or e.Item.ItemType = ListItem.AlternatingItem Then
 UserControlType uc = Ctype(e.Item.FindControl("UC", UserControlType)
 uc.empID = your value
End If

where the UserControlType is the name of the class of the user control

Regards,
B..M
0
 

Author Comment

by:Basic
ID: 11764758
No i am still not able to get it..here is my code


 If (e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem) Then

         
            Dim P As New usercontrolType

            P = CType(e.Item.FindControl("UC"), usercontrolType)
            P. empID = 1234


    End If

-------------------------------------------------
and on myusercontrol page_load code i wrote

response.write ("ID=" & empID)

which shows empty

0
 
LVL 28

Accepted Solution

by:
mmarinov earned 175 total points
ID: 11764817
where do you write reponse.write in your usercontrol?
i think that it is before the empID property be assigned

try this

 Public Property empID() As Integer
        Get
            Return ID
        End Get
        Set(ByVal Value As Integer)

            ID = Value
            Response.Write ( "ID=" & ID & " on the setting" ) 'hope this will work
        End Set
    End Property
0
 

Author Comment

by:Basic
ID: 11764906
yes mmarinov ..its working


i want to Add Id in database

so shall i write code with in  property code?

like...


Public Property empID() As Integer
        Get
            Return ID
        End Get
        Set(ByVal Value As Integer)

            ID = Value
            Response.Write ( "ID=" & ID & " on the setting" ) 'hope this will work
         
           .....................
           .......................
          'database code

        End Set
    End Property


0
 
LVL 28

Expert Comment

by:mmarinov
ID: 11764957
no, you sould not do that
where in the user control you try to access the empID property?
take a look at this page to see the order of events when use a user control and click a button whitin the user control :
http://dotnet.dwteam.com/demos/pageevents.aspx

Regards,
B..M
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:Basic
ID: 11765049
yes i do two things

1)on page_load of user control i have to display the ID on usercontrol label
2)and on clicking a button i have to save the ID along with other textbox value to database
0
 
LVL 28

Expert Comment

by:mmarinov
ID: 11765164
the problem is that the onclick event of the user control's button is executed after it's page load
so may be you recreate the user control between the Pageload event of the page and the onclick event
you have to recheck your code

Regards,
B..M
0
 

Author Comment

by:Basic
ID: 11765202
mmarinov ..i am not able to get u
please..can u  elaborate more
0
 

Author Comment

by:Basic
ID: 11765399
mmarinov ..
thanks for your time :)
0
 

Author Comment

by:Basic
ID: 11765424
0
 

Expert Comment

by:dandancast
ID: 37879053
mmarinov, could you post the whole solution here please? I got the same question.

Thanks for your time.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now