Solved

user control properties in datagrid

Posted on 2004-08-10
11
452 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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
 

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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

752 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