Hi Aussie,
Thank you for your post.
Based on my understanding, your question is how to refresh the DataGrid on
the content page when the DropDownList's selected value changes on the
master page. If I've misunderstood anything, please feel free to post
here.
If you're using DataSource's ControlParameter to select data, you can
actually reference the DropDownList in the content page directly:
<asp
ataGrid ID="grid1" runat="server" DataSourceID="SqlDataSource1">
</asp
ataGrid>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
SelectCommand="SELECT [ProductID], [ProductName], [CategoryName]
FROM [Alphabetical list of products] WHERE ([CategoryID] = @CategoryID)">
<SelectParameters>
<asp:ControlParameter ControlID="ddlType" Name="CategoryID"
PropertyName="SelectedValue"
Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
And here's the content of the master page:
<asp
ropDownList ID="ddlType" runat="server" AutoPostBack="True"
DataSourceID="SqlDataSource1"
DataTextField="CategoryName" DataValueField="CategoryID">
</asp
ropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
SelectCommand="SELECT [CategoryID], [CategoryName] FROM
[Categories]"></asp:SqlDataSource>
=====
Another approach is to define an event in the master page, raise the event
in master page when the DropDownList's selected index is changed, and
handle the event in the content page:
1) Prepare an event argument class and a delegate (I assume the
DropDownList's SelectedValue proproperty is an Int32):
public class SelectedValueChangedArgs : EventArgs
{
private int _id;
public int ID
{
get { return _id; }
set { _id = value; }
}
public SelectedValueChangedArgs(int id)
{
_id = id;
}
}
public delegate void SelectedValueChangedHandler(object sender,
SelectedValueChangedArgs e);
2) Declare an event in the master page and raise it in the DropDownList's
SelectedIndexChanged event:
public event SelectedValueChangedHandler SelectedValueChanged;
protected void ddlType_SelectedIndexChanged(object sender, EventArgs e)
{
if (SelectedValueChanged != null)
{
SelectedValueChanged(this, new
SelectedValueChangedArgs(Int32.Parse( ddlType.SelectedValue)));
}
}
3) In the content page's ASPX source, add an @ MasterType directive so
that
we can use a strongly typed Master reference:
<%@ MasterType VirtualPath="~/MasterPage.master" %>
4) In the content page's code-behind class, handle the master page's
SelectedValueChanged event:
protected void Page_Load(object sender, EventArgs e)
{
Master.SelectedValueChanged += new
SelectedValueChangedHandler(Master_SelectedValueChanged);
}
void Master_SelectedValueChanged(object sender,
SelectedValueChangedArgs e)
{
int id = e.ID;
}
Hope this helps. Please feel free to post here if anything is unclear.
Regards,
Walter Wang (
[email protected], remove 'online.')
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no
rights.