Hello Bruno,
As for the DataSource control referencing problem, it is caused by the
DataSourceControl and ParamterSource control are in different
ContentPlaceHolder of the Master_Content page. The DataSourceControl can
only locate control that are in the same parent container, for master page
with multiple contentPlaceHolders, controls in different Content holder can
not be found by DataSourceControl 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:SqlDataSource ...............>
<SelectParameters>
<asp:Parameter DefaultValue="" Name="CategoryID" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
===========
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 DataSourceControl's "Selecting" event. e.g
=-=============
protected void SqlDataSource1_Selecting(object sender,
SqlDataSourceSelectingEventArgs e)
{
e.Command.Parameters["@CategoryID"].Value =
int.Parse(txtCategory.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 DataSourceControl and let
DataSourcecontrol's ControlParameter 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" ContentPlaceHolderID="ContentPlaceHolder1"
Runat="Server">
<asp:TextBox ID="txtCategory" runat="server"
OnLoad="txtCategory_Load">1</asp:TextBox>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder2"
Runat="Server">
<asp:TextBox ID="txtTemp" runat="server" Visible="false"></asp:TextBox>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
OnSelecting="SqlDataSource1_Selecting" SelectCommand="SELECT
[CategoryID], [CategoryName] FROM [Categories] WHERE ([CategoryID] =
@CategoryID)">
<SelectParameters>
<asp:ControlParameter ControlID="txtTemp" PropertyName="Text"
Name="CategoryID" DefaultValue="1" />
</SelectParameters>
</asp:SqlDataSource>
<asp:DetailsView ID="DetailsView1" runat="server"
AutoGenerateRows="False" DataKeyNames="CategoryID"
DataSourceID="SqlDataSource1" Height="50px" Width="125px">
<Fields>
<asp:BoundField DataField="CategoryID" HeaderText="CategoryID"
InsertVisible="False"
ReadOnly="True" SortExpression="CategoryID" />
<asp:BoundField DataField="CategoryName"
HeaderText="CategoryName" SortExpression="CategoryName" />
</Fields>
</asp:DetailsView>
<asp:Button ID="Button1" runat="server" Text="Button"
OnClick="Button1_Click" />
</asp:Content>
========================================
=========code behind================
protected void txtCategory_Load(object sender, EventArgs e)
{
txtTemp.Text = txtCategory.Text;
}
=-=====================
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.