Solved

user control properties in datagrid

Posted on 2004-08-10
11
456 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

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
 

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
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.
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Suggested Courses

624 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