Hello Bruno,
As for the DataSource control referencing problem, it is caused by the
DataSourceContr ol and ParamterSource control are in different
ContentPlaceHol der of the Master_Content page. The DataSourceContr ol can
only locate control that are in the same parent container, for master page
with multiple contentPlaceHol ders, controls in different Content holder can
not be found by DataSourceContr ol in other content holder.
Based on my research, you can consider using the following ways to overcome
the problem:
1. Instead of using ControlParamter , you can define a normal parameter
which doesn't has a linked source (control, querystring.... ). e.g
==========
<asp:SqlDataSou rce ............... >
<SelectParamete rs>
<asp:Paramete r DefaultValue="" Name="CategoryI D" Type="Int32" />
</SelectParameter s>
</asp:SqlDataSour ce>
===========
And runtime, you programmtically retrieve parameter value from the source
control and add the value into Select Command's parameter, you can do it in
the DataSourceContr ol's "Selecting" event. e.g
=-=============
protected void SqlDataSource1_ Selecting(objec t sender,
SqlDataSourceSe lectingEventArg s e)
{
e.Command.Param eters["@CategoryI D"].Value =
int.Parse(txtCa tegory.Text);
}
=============== ===
2. Since the cause of the problem is due to paramter control and datasource
control in different Content Holder, you can add a hidden TextBox control
in the same contentHolder of the DataSourceContr ol and let
DataSourcecontr ol's ControlParamete r refer to this hidden control, and you
need to add some code in the original TextBox.Load event to synchronize the
value between them. e.g
#the following page use a hiddden TextBox(txtTemp ) to act as a linker
between the two content holder to pass parameter value.
=============== ===========
<asp:Content ID="Content1" ContentPlaceHol derID="ContentP laceHolder1"
Runat="Server">
<asp:TextBox ID="txtCategory " runat="server"
OnLoad="txtCate gory_Load">1</asp:TextBox>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHol derID="ContentP laceHolder2"
Runat="Server">
<asp:TextBox ID="txtTemp" runat="server" Visible="false" ></asp:TextBox>
<asp:SqlDataSou rce ID="SqlDataSour ce1" runat="server"
ConnectionStrin g="<%$ ConnectionStrin gs:NorthwindCon nectionString %>"
OnSelecting="Sq lDataSource1_Se lecting" SelectCommand=" SELECT
[CategoryID], [CategoryName] FROM [Categories] WHERE ([CategoryID] =
@CategoryID)">
<SelectParamete rs>
<asp:ControlPar ameter ControlID="txtT emp" PropertyName="T ext"
Name="CategoryI D" DefaultValue="1 " />
</SelectParameter s>
</asp:SqlDataSour ce>
<asp:DetailsVie w ID="DetailsView 1" runat="server"
AutoGenerateRow s="False" DataKeyNames="C ategoryID"
DataSourceID="S qlDataSource1" Height="50px" Width="125px">
<Fields>
<asp:BoundFie ld DataField="Cate goryID" HeaderText="Cat egoryID"
InsertVisible=" False"
ReadOnly="True" SortExpression= "CategoryID " />
<asp:BoundFie ld DataField="Cate goryName"
HeaderText="Cat egoryName" SortExpression= "CategoryNa me" />
</Fields>
</asp:DetailsView >
<asp:Button ID="Button1" runat="server" Text="Button"
OnClick="Button 1_Click" />
</asp:Content>
=============== =============== ==========
=========code behind========= =======
protected void txtCategory_Loa d(object sender, EventArgs e)
{
txtTemp.Text = txtCategory.Tex t;
}
=-=============== ======
Hope this helps. If there is anything unclear, please feel free to let me
know.
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.