Solved

user control properties in datagrid

Posted on 2004-08-10
11
443 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

910 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

22 Experts available now in Live!

Get 1:1 Help Now