Solved

user control properties in datagrid

Posted on 2004-08-10
11
450 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

830 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