473,405 Members | 2,185 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Learing ?

Hi,

I have a master page that contains a dropdownlist control, and a content
page with a datagrid on it.

When the user changes the selecteditem in the drop down, I want to refresh
the datagrid with new data (from a sql stored proc).

From the masterpage code, how can I access the content pages dataview
control ?

Thanks

Jul 24 '06 #1
5 1304
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:DataGrid ID="grid1" runat="server" DataSourceID="SqlDataSource1">
</asp:DataGrid>
<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:DropDownList ID="ddlType" runat="server" AutoPostBack="True"
DataSourceID="SqlDataSource1"
DataTextField="CategoryName" DataValueField="CategoryID">
</asp:DropDownList>
<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_SelectedValueCh anged);
}

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 (wa****@online.microsoft.com, 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.

Jul 25 '06 #2
Hi,

Thanks for you reply, but I am a bit lost on it.

My drop down list is not bound, I populate it in the page_load event in the
code behind file.

Is there a way in the dropdownlist.selectedindexchanged event (on master
page) to call sub on the content page. The sub on the content page would do
the work and update the grid itself. (the grid is also unbound).

Thanks.

Heath

"Walter Wang [MSFT]" <wa****@online.microsoft.comwrote in message
news:%2****************@TK2MSFTNGXA01.phx.gbl...
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:DataGrid ID="grid1" runat="server" DataSourceID="SqlDataSource1">
</asp:DataGrid>
<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:DropDownList ID="ddlType" runat="server" AutoPostBack="True"
DataSourceID="SqlDataSource1"
DataTextField="CategoryName" DataValueField="CategoryID">
</asp:DropDownList>
<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_SelectedValueCh anged);
}

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 (wa****@online.microsoft.com, 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.

Jul 29 '06 #3
Hi,

You can make changes only in the Content Page:

protected void Page_Load(object sender, EventArgs e)
{
DropDownList ddlType = (DropDownList) Master.FindControl("ddlType");
ddlType.SelectedIndexChanged += new
EventHandler(ddlType_SelectedIndexChanged);
}

void ddlType_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList ddlType = (DropDownList) sender;
object o = ddlType.SelectedValue;
}

Hope this helps. Please feel free to post here if anything is unclear.

Regards,
Walter Wang (wa****@online.microsoft.com, 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.

Jul 31 '06 #4
Hi,

I have been able to code where an event on the content page results in a
update on the master page. My learning example is as simple as entering text
into a text box on the content page and clicking a button, then using the
find control to find a label on the master page and update its .text
property.

My problem is the reverse of this. I want a control on the master page to
update the control on the content page.

Infact I have worked out that probably the best solution, is on the
selectedindexchange event, i actually just call the content page,and pass a
parameter on the URL string, then in the content page, pickup the parameter,
and do what i need to do in the page load event.

I have worked out the page.response.redirect, and will build the parameter
up in their, but how do I get a ?genre=1 in the content page.

THanks

"Walter Wang [MSFT]" <wa****@online.microsoft.comwrote in message
news:f7**************@TK2MSFTNGXA01.phx.gbl...
Hi,

You can make changes only in the Content Page:

protected void Page_Load(object sender, EventArgs e)
{
DropDownList ddlType = (DropDownList)
Master.FindControl("ddlType");
ddlType.SelectedIndexChanged += new
EventHandler(ddlType_SelectedIndexChanged);
}

void ddlType_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList ddlType = (DropDownList) sender;
object o = ddlType.SelectedValue;
}

Hope this helps. Please feel free to post here if anything is unclear.

Regards,
Walter Wang (wa****@online.microsoft.com, 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.

Aug 1 '06 #5
Hi Aussie,

The "?genre=1" is called QueryString, you can read it in Content Page's
Page_Load:

string s = Request.QueryString["genre"];
if (s != null && s.Length 0)
{
int genre = Int32.Parse(s);
// handle this parameter
}

However, your approach will cause one additional postback.

Another solution is to handle the DropDownList's SelectedIndexChanged event
in the Master Page directly. We can use following code to find the Grid
control on the Content Page:

private Control FindControlRecursive(Control root, string id)
{
if (root.ID == id)
{
return root;
}

foreach (Control c in root.Controls)
{
Control t = FindControlRecursive(c, id);
if (t != null)
{
return t;
}
}

return null;
}

protected void ddlType_SelectedIndexChanged(object sender, EventArgs e)
{
DataGrid grid = (DataGrid) FindControlRecursive(Page, "grid1");
// control this DataGrid from Master Page
}

Hope this helps. Please feel free to post here if anything is unclear.

Regards,
Walter Wang (wa****@online.microsoft.com, 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.

Aug 2 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: sarah rosen | last post by:
For a NON-Technical person how easy is it to learn PHP ? (for website changes - mostly minor changes)I have never done any programming. If any one would be kind enough to let me know I would...
5
by: Micha³ Wo¼niak | last post by:
Hi again The Question of Logs, part II. :) What are the advantages/disadvantages of using syslog() to do the logging rather than writing the logs with fopen(), fwrite() and fclose()? What...
5
by: Steve Gdula | last post by:
I am wondering if anyone knows if it is possible to change the display orientation of a label so that the text may be displayed vertically rather than horizontally. I have seen reference to API...
2
by: Mel Roman | last post by:
Hi: As someone who's learing Java, I've been monitoring this newsgroup for a while now. I've recently been struck by the fact that the traffic on this newsgroup is much lower than those for...
0
by: Raymond Arthur St. Marie II of III | last post by:
Del's "except"ional PEP Rejection Ladieees and Gentilmen and Pyth-O-neers of all ages. Step right up. Don't be shy. Come one come all. Be the first on your block TO GROK *THE* one *THE* only...
43
by: 3seas | last post by:
If you are not interested, then don't bitch, its a short message. http://www.matrixcommunity.org/cgi-bin/ultimatebb.cgi?ubb=get_topic;f=8;t=000918 I don't know if that link got broken. -- 3...
18
by: Antoon Pardon | last post by:
I have made a module derived from the Queue module deliverd with python 2.3. I would like to make this module (called tube) available for other people. However it is not clear to me how I can do...
1
by: Patrick Useldinger | last post by:
Hi All, I have some experience with C, Pascal, COBOL and lately Python, and am quite confident with all of these. I would like to learn Perl as well, and I am looking for a decent tutorial which...
1
by: Sen | last post by:
1. Where are the best to start learing VB.Net, currently I am using Visual Foxpro as my depelopment tools 2. How to generate menu at run time, the menu it self is stored at database table, are...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.