How do I control parameter a control that is inside a formview that has another formview in it?

I have a formview2 within another formview1 but I want to control parameter from a sqlDataSource3 outside the formview a control that is in formview2

<asp:SqlDataSource ID="SqlDataSource1" SelectCommand='SELECT "USER,UID" FROM "TUSERS"'>
<asp:FormView ID="FormView1" runat="server" DataSourceID="SqlDataSource1">
    <ItemTemplate>

        <asp:Label ID="Label1" runat="server" Text='<%# Bind("USER") %>'></asp:Label><br />
        <asp:Label ID="Label2" runat="server" Text='<%# Bind("UID") %>'></asp:Label><br />

        <asp:FormView ID="FormView2" runat="server" DataSourceID="SqlDataSource2">
           <ItemTemplate>
              <asp:Label ID="Label3" runat="server" Text='<%# Bind("SALARY") %>'></asp:Label><br />
              <asp:Label ID="Label4" runat="server" Text='<%# Bind("SID") %>'></asp:Label><br />
           </ItemTemplate>
        </asp:FormView>

        <asp:SqlDataSource ID="SqlDataSource2" SelectCommand='SELECT "SALARY,SID" FROM "TSALARY" WHERE ("UID" = :UID)'>
           <SelectParameters>
              <asp:ControlParameter ControlID="Label2" Name="UID" PropertyName="Text" Type="Decimal" />
           </SelectParameters>
       </asp:SqlDataSource>

    </ItemTemplate>
</asp:FormView>


<asp:SqlDataSource ID="SqlDataSource3" SelectCommand='SELECT "details" FROM "tdetails" WHERE ("SID" = :SID)'>
  <SelectParameters>
    <asp:ControlParameter ControlID="Label4" Name="UID" PropertyName="Text" Type="Decimal" />
    </SelectParameters>
</asp:SqlDataSource>


The bold line does not work

 How do I access Label4 from code?

I tried: Page.findControl("Label4") but null the same way as Formview2.findControl("Label4") and nothing.
 

0
jleviaguirre
8/30/2007 9:20:52 PM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

6 Replies
1675 Views

Similar Articles

[PageSpeed] 13
Get it on Google Play
Get it on Apple App Store

Because FormView2 is within a container (FormView1) it is not accessible directly.  You have to get the topmost parent and then traverse through the tree. 

dim fv2 as FormView = CType(FormView1.FindControl("FormView2"), FormView)
if fv2 isnot nothing then
 dim lbl as Label = Ctype(fv2.FindControl("Label4"), Label)
 if lbl isnot nothing then
    Msg.Text = "found the label and its value is: " & lbl.text
 end if
end if
 
0
codeasp
8/30/2007 9:35:18 PM

Since your Label4 is inside the formView2, Try this

FormView FormView2 = FormView1.FindControl("FormView2")   as FormView;

Label Label4 = FormView2.FindControl("Label4") as Label; 

 

This should work 

 


Raghu
(MCSD.NET, MCAD.NET, MCDBA)
[Don't forget to click on Mark as answer on the post that helped you ]
0
rmaiya
8/30/2007 9:36:46 PM

Great! thanks

But how do I make Repeater1 bind after I set Label5.Text?


 

<asp:Label ID="Label5" Text="0"></asp:Label>

<asp:SqlDataSource ID="SqlDataSource3" SelectCommand='SELECT "details" FROM "tdetails" WHERE ("SID" = :SID)'>
  <SelectParameters>
    <asp:ControlParameter ControlID="Label5" Name="UID" PropertyName="Text" Type="Decimal" />
    </SelectParameters>
</asp:SqlDataSource>
 

<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSourceCategories">
<ItemTemplate>
<%#myMethod(Eval("details"))%>
</ItemTemplate>
</asp:Repeater>

 
        protected void bindLabel5() { //sets label5.text to whatever the buried label4.text databounded value is
FormView fv = FormView1.FindControl("FormView2") as FormView;
if (fv != null) {
Label l = fv.FindControl("Label4") as Label;
if (l != null) Label5.Text = l.Text;
}
}
 

  Where in the code should i call bindLabel5 to first set the label5.text and then Repeater1.DataBind()?
0
jleviaguirre
8/30/2007 11:23:37 PM

Rebind the Repeater to the datasource, which will (should) fire the Select event of the SqlDataSource.

0
codeasp
8/30/2007 11:41:14 PM

ok, here is what I am trying to do:

 1. A formView2 databinds after his parent formView1 binds.

2. When FormView2 binds, label5.text is updated

3. Repeater3 binds after label5.text is updated

But it seems that all the databindings are happening before the label5.text updates.

0
jleviaguirre
8/31/2007 2:59:44 AM

Hi:

  You can use <asp:Parameter /> instead of ControlParameter and in SqlDataSource's Selecting event handler you can manually assign value to the parameter:

 protected void SqlDataSource3_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
    {

//        e.Command.Parameters[0].Value=...//Use FindControl method to find the Labe, assign it's Text to the parameter

    }

  If it doesn't work, please inform us.

Regards


Sincerely,
Allen Chen
Microsoft Online Community Support

Please remember to mark the replies as answers if they help and unmark them if they provide no help.
0
Allen
9/4/2007 8:09:52 AM
Reply:

Similar Artilces:

SqlDataSource with FormView: Referencing a control inside FormView as control parameter?
I have been looking at this website and was wondering...what if my FormView control had a textbox or label inside of it in its EditTemplate item...can I link my SqlDataSource object (which is also bound to the FormView control) to that control meaning specify control parameter as the textbox which is inside the FormView...? PS: I use vbexpress 2005 programming blog Hi:   You can try something like: <asp:ControlParameter ControlID="FromView1$DropDownList1"   But please make sure the DropDownList (or any other controls) be available all the time. In anoth...

Cascading Dropdown error in formview controls and finding all controls in formview controls
can help with the following? Instantiate Cascading Dropdowns within Formview controls (this returns the error message "databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control".) Pass values between controls within master controls such as Textboxes within formviews (example: Pass the selected value in a dropdownlist to another textbox both WITHIN a formview control) Expose the public properties of a master page Hi arraybiz, 1) I need your code. See sample: http://www.mikepope.com/blog/fun/cascadingdropdowns_dy...

Referencing Nested FormView Control inside the EmptyDataTemplate of a FormView Control
Hi all,I am very new to ASP.Net and have been working on a particularly frustrating problem now for days and cant seem to find an answer to it. I am building a front end to a newly created database and have set 2 session variables that I am using to set default values using the FindControl Method. this works fine until I need to set default values in a nested control. IE...I have a form view control and in that controls EmptyDataTemplate I have another form view control with about 10 fields using the same datasource as the parent form view. I need to place default values in 2 of those fields...

controls not visible inside formview control
I am trying to write a query to select data from one table based on the resultof a drop down list that pulls data from another table. The query I am writing is: "SELECT church.churchName, church.churchId AS Expr1 FROM [churches]WHERE ([deanery.deaneryId] = @churches.deaneryId)"I am using a sql source controlNow I found an example from a website that pulls data from one drop down list and usesthe selected value to populate the second drop down list. But, the controls are not part of a formviewcontrol. So my question is how do I get the dropdownlist control that is located...

Controls inside formview inside formview
Hello, I'm trying to insert data into a label that is located in a formview which is located in a formview.  This is what I got so far: Private Sub Test()    Dim fvSecondView As New FormView    fvSecondView = Me.FormView1.FindControl("SecondView")    Dim lblData As New Label    lblData = fvSecondView.FindControl("DataLabel")    lblData.Text = "Some Data" End Sub Now this does work to get data out if I change the last line to: testlabel.text = lblData.Text But just can't seem to get the data to go ...

How do I control one control from another control?
I have a page page1.aspx which is within a master page. On page I have a table with two cells. Within each cell I have placed two controls (ascx) that I have developed. Now I'd like to be able to get these two controls to interact. One needs to update the other. One has some search criteria that the other one needs to update its gridview. One needs to make the other visible/not visible at certain times. Out of the box neither control can see each other at all. Is there a good article or someplace I can find some information on how to do this?  AllAboutFocus.com. Information Technolo...

How to concatenate values from Formview controls into another control?
I have a formview, a portion of which is below. I need to take the values from ddlregion, landowner_lastnameTextBox and intransfer_transfer_dateTextBox, then when the Insert button is clicked, place them in primary_key2TextBox in the format region-lastname-date. ie NE-Jimbo-071708. Date is orginally going to be a full time-datestamp, such as "07/17/08 12:00:00" I know Findcontrol is used somehow, but so far I haven't found how to concatenate values together in any that I can unserstand. I'm using VB.net. Please, no C# or javascript examples. <InsertItemTemplate>&nbs...

Formview inside a formview controller
Hi all, I'm using a formview(say formview1) controller to insert a records to a table. I take a value from a dropdownlist which i have placed in  the InsertItemTemplete of the formview1. Lets say the dropdownlist has list of towns and I need to add a new town to the list while the user is in the insert template. To do this I have added another formview (say formview2) to inser a new record to the towns table. My problem is my dropdown list is not getting updated just after I have added a new town. But if I start insert operation all over again then I can see the new town. I know t...

Controller inside another controller...
Sorry, I dont know if this make any sense...My doubt is, suppose  that I have a CourseController, and there is two types of courses.. public and private...If I wanna have a CourseController, with action List, to list both types of courses.. And, route /course/public/{index,save,edit,delete} to public courses, and route /course/private/{index,save,edit,delete}...Is this possible to do? Or I have to create CoursePublicController and CoursePrivateController?How do I model this?I tried to look at ASP.NET MVC Controller Tutorials.. but its all basics...  Thanks.. It could be don...

How access controls in formview control?
I have a Lable control inside of a Formview control Empty Template. How do I access the lable control in the empty tamplate in the databound method? Try:if (FormView1.Row.RowType == DataControlRowType.EmptyDataRow) { Label l = (Label)FormView1.FindControl("Label1"); if (l = !null) { l.Text = "Found a label"; } }  Regards,Vinz"Code, Beer and Music" that's my way of being a programmer!How to get your Forum Question Answered | Blog | CodeASP.NET vinz:Try:if (FormView1.Row.RowType == DataControlRowTy...

Formview control with in Wizard control
I have a wizard control in which it promts the user if he is a delaer or customer. on next step it displays the result. Results are almost same for both dealer and customer but for customer I need to remove few things. How can I take care of this? one thing I can do is create unique steps for dealer and customer. There shoud be a work around just to hide few items. With in formcontrol I am using table? How can I have different color for each row and column within form to make is easy for user to read? Is there some template property I need to use for form? you can use wizard step events...

Trying to load a control into a control from another control
Exactly as the subject states, I'm trying to load a control into another control from a control loaded into a page, I keep getting this error from the code I have below. I've also tried the findcontrol but it keeps coming up null. (67): 'System.Web.UI.UserControl' denotes a 'class' where a 'variable' was expected UserControl ut = ((webcontrols.BrowseItems)UserControl).LoadControl("BrowseItems"); ((webcontrols.BrowseItems)UserControl).pnl_browse_main.Controls.Add(ut); This is how we Load User controls into a content place holder. try { UserCont...

Using a Custom Control inside of FormView
Hello, I just finished converting my system from the Atlas CTP to AJAX Beta.  After correcting all of the tags I noticed that there is a problem with a control that I had built with the Atlas CTP.  My control is similar to the calendar control on the AJAX ControlTool kit Popup Control example. ( http://ajax.asp.net/ajaxtoolkit/PopupControl/PopupControl.aspx )  When using the control inside of a Formview (or Gridview) the calendar popup does not popup when the textbox takes focus unless the update panel that contains the Formview has been updated since the page load.  I ha...

Hiding a control in a formview depending on the value of another control (VB)
Hi,I have a formview with a number of controls in it. The formview's default display mode is 'Edit', and the form is filled from a selection made from a Gridview.I want to be able to hide a checkbox dependant on whether a textbox contains a certain value.     Sub hidecontrol()        Dim field1 = FormView1.FindControl("TextBox1")        If field1.text = "mytext" Then FormView1.FindControl("CheckBox3").Visible = False    End Sub Sorry, I'm a no...