PC Review


Reply
Thread Tools Rate Thread

Changing the datasource.Id of a grid as its page is opening

 
 
Monty
Guest
Posts: n/a
 
      3rd Apr 2006
Hi there,
From one page, I have created a dropdown list of employees. When an employee
is selected, I would like another page to open, based upon the employee.
Here is my question...
How do I change the datasource.id of a grid on another page as it is
opening?
Thank you, Mark


 
Reply With Quote
 
 
 
 
Ken Cox - Microsoft MVP
Guest
Posts: n/a
 
      3rd Apr 2006
You just need to pass the selected value on a query string to the second
page and pick it up there.

Here's the idea. Let us know if it helps?

Ken
Microsoft MVP [ASP.NET]


Here's pg1.aspx

<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

Protected Sub Button1_Click _
(ByVal sender As Object, _
ByVal e As System.EventArgs)
Response.Redirect("pg2.aspx?id=" & _
DropDownList1.SelectedValue.ToString)

End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:dropdownlist id="DropDownList1" runat="server">
<asp:listitem value="0">George</asp:listitem>
<asp:listitem value="1">John</asp:listitem>
<asp:listitem value="2">Mary</asp:listitem>
</asp:dropdownlist><br />
<br />
<asp:button id="Button1" runat="server" onclick="Button1_Click"
text="Button" />&nbsp;</div>
</form>
</body>
</html>

Here's pg2.aspx

<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

Protected Sub Page_Load _
(ByVal sender As Object, _
ByVal e As System.EventArgs)
Dim strID As String
If Not IsNothing(Request("id")) Then
strID = Request("id")
Label1.Text = strID
dg.DataSourceID = strID
End If

End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:label id="Label1" runat="server"></asp:label><br />
<br />
<asp:datagrid id="dg" runat="server" ></asp:datagrid></div>
</form>
</body>
</html>


"Monty" <(E-Mail Removed)> wrote in message
news:GvZXf.405$(E-Mail Removed)...
> Hi there,
> From one page, I have created a dropdown list of employees. When an
> employee is selected, I would like another page to open, based upon the
> employee. Here is my question...
> How do I change the datasource.id of a grid on another page as it is
> opening?
> Thank you, Mark
>



 
Reply With Quote
 
Monty
Guest
Posts: n/a
 
      4th Apr 2006
Ken, thank you. It works well.
If you could, could you expand on the ?id in your code as follows...
"Response.Redirect("pg2.aspx?id=" & _"
Thanks again, Mark

"Ken Cox - Microsoft MVP" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> You just need to pass the selected value on a query string to the second
> page and pick it up there.
>
> Here's the idea. Let us know if it helps?
>
> Ken
> Microsoft MVP [ASP.NET]
>
>
> Here's pg1.aspx
>
> <%@ Page Language="VB" %>
>
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
>
> <script runat="server">
>
> Protected Sub Button1_Click _
> (ByVal sender As Object, _
> ByVal e As System.EventArgs)
> Response.Redirect("pg2.aspx?id=" & _
> DropDownList1.SelectedValue.ToString)
>
> End Sub
> </script>
>
> <html xmlns="http://www.w3.org/1999/xhtml" >
> <head runat="server">
> <title>Untitled Page</title>
> </head>
> <body>
> <form id="form1" runat="server">
> <div>
> <asp:dropdownlist id="DropDownList1" runat="server">
> <asp:listitem value="0">George</asp:listitem>
> <asp:listitem value="1">John</asp:listitem>
> <asp:listitem value="2">Mary</asp:listitem>
> </asp:dropdownlist><br />
> <br />
> <asp:button id="Button1" runat="server" onclick="Button1_Click"
> text="Button" />&nbsp;</div>
> </form>
> </body>
> </html>
>
> Here's pg2.aspx
>
> <%@ Page Language="VB" %>
>
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
>
> <script runat="server">
>
> Protected Sub Page_Load _
> (ByVal sender As Object, _
> ByVal e As System.EventArgs)
> Dim strID As String
> If Not IsNothing(Request("id")) Then
> strID = Request("id")
> Label1.Text = strID
> dg.DataSourceID = strID
> End If
>
> End Sub
> </script>
>
> <html xmlns="http://www.w3.org/1999/xhtml" >
> <head runat="server">
> <title>Untitled Page</title>
> </head>
> <body>
> <form id="form1" runat="server">
> <div>
> <asp:label id="Label1" runat="server"></asp:label><br />
> <br />
> <asp:datagrid id="dg" runat="server" ></asp:datagrid></div>
> </form>
> </body>
> </html>
>
>
> "Monty" <(E-Mail Removed)> wrote in message
> news:GvZXf.405$(E-Mail Removed)...
>> Hi there,
>> From one page, I have created a dropdown list of employees. When an
>> employee is selected, I would like another page to open, based upon the
>> employee. Here is my question...
>> How do I change the datasource.id of a grid on another page as it is
>> opening?
>> Thank you, Mark
>>

>
>



 
Reply With Quote
 
Monty
Guest
Posts: n/a
 
      4th Apr 2006
Thanks, it worked fine.
Can you explain the ?id in your code?
"Response.Redirect("pg2.aspx?id=" & _"
Thanks again, Mark

"Ken Cox - Microsoft MVP" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> You just need to pass the selected value on a query string to the second
> page and pick it up there.
>
> Here's the idea. Let us know if it helps?
>
> Ken
> Microsoft MVP [ASP.NET]
>
>
> Here's pg1.aspx
>
> <%@ Page Language="VB" %>
>
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
>
> <script runat="server">
>
> Protected Sub Button1_Click _
> (ByVal sender As Object, _
> ByVal e As System.EventArgs)
> Response.Redirect("pg2.aspx?id=" & _
> DropDownList1.SelectedValue.ToString)
>
> End Sub
> </script>
>
> <html xmlns="http://www.w3.org/1999/xhtml" >
> <head runat="server">
> <title>Untitled Page</title>
> </head>
> <body>
> <form id="form1" runat="server">
> <div>
> <asp:dropdownlist id="DropDownList1" runat="server">
> <asp:listitem value="0">George</asp:listitem>
> <asp:listitem value="1">John</asp:listitem>
> <asp:listitem value="2">Mary</asp:listitem>
> </asp:dropdownlist><br />
> <br />
> <asp:button id="Button1" runat="server" onclick="Button1_Click"
> text="Button" />&nbsp;</div>
> </form>
> </body>
> </html>
>
> Here's pg2.aspx
>
> <%@ Page Language="VB" %>
>
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
>
> <script runat="server">
>
> Protected Sub Page_Load _
> (ByVal sender As Object, _
> ByVal e As System.EventArgs)
> Dim strID As String
> If Not IsNothing(Request("id")) Then
> strID = Request("id")
> Label1.Text = strID
> dg.DataSourceID = strID
> End If
>
> End Sub
> </script>
>
> <html xmlns="http://www.w3.org/1999/xhtml" >
> <head runat="server">
> <title>Untitled Page</title>
> </head>
> <body>
> <form id="form1" runat="server">
> <div>
> <asp:label id="Label1" runat="server"></asp:label><br />
> <br />
> <asp:datagrid id="dg" runat="server" ></asp:datagrid></div>
> </form>
> </body>
> </html>
>
>
> "Monty" <(E-Mail Removed)> wrote in message
> news:GvZXf.405$(E-Mail Removed)...
>> Hi there,
>> From one page, I have created a dropdown list of employees. When an
>> employee is selected, I would like another page to open, based upon the
>> employee. Here is my question...
>> How do I change the datasource.id of a grid on another page as it is
>> opening?
>> Thank you, Mark
>>

>
>



 
Reply With Quote
 
Ken Cox - Microsoft MVP
Guest
Posts: n/a
 
      4th Apr 2006
Hi Mark,

The part starting with the question mark (?) is called a querystring. It
simulates the Get technique in HTTP, requesting a resource by providing
additional data.

The format is a name/value pair separated by an equals (-) sign as in

id=444

You can read lots more here by searching for request querystring on the MSDN
site.

Ken


"Monty" <(E-Mail Removed)> wrote in message
news:OljYf.301$(E-Mail Removed)...
> Ken, thank you. It works well.
> If you could, could you expand on the ?id in your code as follows...
> "Response.Redirect("pg2.aspx?id=" & _"
> Thanks again, Mark
>
> "Ken Cox - Microsoft MVP" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> You just need to pass the selected value on a query string to the second
>> page and pick it up there.
>>
>> Here's the idea. Let us know if it helps?
>>
>> Ken
>> Microsoft MVP [ASP.NET]
>>
>>
>> Here's pg1.aspx
>>
>> <%@ Page Language="VB" %>
>>
>> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
>> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
>>
>> <script runat="server">
>>
>> Protected Sub Button1_Click _
>> (ByVal sender As Object, _
>> ByVal e As System.EventArgs)
>> Response.Redirect("pg2.aspx?id=" & _
>> DropDownList1.SelectedValue.ToString)
>>
>> End Sub
>> </script>
>>
>> <html xmlns="http://www.w3.org/1999/xhtml" >
>> <head runat="server">
>> <title>Untitled Page</title>
>> </head>
>> <body>
>> <form id="form1" runat="server">
>> <div>
>> <asp:dropdownlist id="DropDownList1" runat="server">
>> <asp:listitem value="0">George</asp:listitem>
>> <asp:listitem value="1">John</asp:listitem>
>> <asp:listitem value="2">Mary</asp:listitem>
>> </asp:dropdownlist><br />
>> <br />
>> <asp:button id="Button1" runat="server" onclick="Button1_Click"
>> text="Button" />&nbsp;</div>
>> </form>
>> </body>
>> </html>
>>
>> Here's pg2.aspx
>>
>> <%@ Page Language="VB" %>
>>
>> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
>> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
>>
>> <script runat="server">
>>
>> Protected Sub Page_Load _
>> (ByVal sender As Object, _
>> ByVal e As System.EventArgs)
>> Dim strID As String
>> If Not IsNothing(Request("id")) Then
>> strID = Request("id")
>> Label1.Text = strID
>> dg.DataSourceID = strID
>> End If
>>
>> End Sub
>> </script>
>>
>> <html xmlns="http://www.w3.org/1999/xhtml" >
>> <head runat="server">
>> <title>Untitled Page</title>
>> </head>
>> <body>
>> <form id="form1" runat="server">
>> <div>
>> <asp:label id="Label1" runat="server"></asp:label><br />
>> <br />
>> <asp:datagrid id="dg" runat="server" ></asp:datagrid></div>
>> </form>
>> </body>
>> </html>
>>
>>
>> "Monty" <(E-Mail Removed)> wrote in message
>> news:GvZXf.405$(E-Mail Removed)...
>>> Hi there,
>>> From one page, I have created a dropdown list of employees. When an
>>> employee is selected, I would like another page to open, based upon the
>>> employee. Here is my question...
>>> How do I change the datasource.id of a grid on another page as it is
>>> opening?
>>> Thank you, Mark
>>>

>>
>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Simple generic list as a datasource for a grid cowznofsky Microsoft ASP .NET 3 12th Jul 2007 10:34 PM
Simple Data Grid DataSource Problem =?Utf-8?B?VGhvbWFz?= Microsoft Dot NET Framework Forms 0 29th Dec 2004 06:47 PM
Checking grid datasource? VM Microsoft C# .NET 1 20th May 2004 06:14 PM
Changing the Page... text in a grid Ian Walsh Microsoft ASP .NET 0 27th Jan 2004 05:46 PM
Easiest way to bind a grid datasource to a datatable =?Utf-8?B?S2VubmV0aA==?= Microsoft ASP .NET 2 18th Jan 2004 01:16 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:42 PM.