Showing posts with label button. Show all posts
Showing posts with label button. Show all posts

Thursday, March 29, 2012

Pass Parameter As DataGridItemEventArgs

A Form has a DataGrid & a Button. The DataGrid's ItemDataBound event
calls a sub named 'BindData'. This sub first finds a Label which exists
in the ItemTemplate of the TemplateColumn of the DataGrid & does some
work with the Label.
Sub BindData(obj As Object, ea As DataGridItemEventArgs)
Dim lbl As Label
If (ea.Item.ItemType = ListItemType.Item Or ea.Item.ItemType =
ListItemType.AlternatingItem) Then
lbl = ea.Item.FindControl("lblAcre")
...
...
End If
End Sub
The Button has the Click event which invokes a sub named 'SubmitPage'.
Sub SubmitPage(obj As Object, ea As EventArgs)
...
End Sub
Now I did like the 'SubmitPage' sub to invoke the 'BindData' sub. How
do I accomplish this? In other words, what parameters do I pass from
the 'SubmitPage' sub to the 'BindData' sub which the latter expects?You can't get DataGridItemEventArgs in SubmitPage (it is event argument data
type specific to a event, so it's not even wise to use as input to a
method), but you can loop through the DataGrid manually.
Sub SubmitPage(obj As Object, ea As EventArgs)
For each dgitem As DataGridItem in DataGrid1.Items
Dim lbl As Label=Nothing
If (dgitem.ItemType = ListItemType.Item Or dgitem.ItemType =
ListItemType.AlternatingItem) Then
lbl = dgitem.FindControl("lblAcre")
'Do something with the Label
End If
Next
End Sub
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke
<rn5a@.rediffmail.com> wrote in message
news:1165068166.263744.157190@.l12g2000cwl.googlegroups.com...
>A Form has a DataGrid & a Button. The DataGrid's ItemDataBound event
> calls a sub named 'BindData'. This sub first finds a Label which exists
> in the ItemTemplate of the TemplateColumn of the DataGrid & does some
> work with the Label.
> Sub BindData(obj As Object, ea As DataGridItemEventArgs)
> Dim lbl As Label
> If (ea.Item.ItemType = ListItemType.Item Or ea.Item.ItemType =
> ListItemType.AlternatingItem) Then
> lbl = ea.Item.FindControl("lblAcre")
> ....
> ....
> End If
> End Sub
> The Button has the Click event which invokes a sub named 'SubmitPage'.
> Sub SubmitPage(obj As Object, ea As EventArgs)
> ....
> End Sub
> Now I did like the 'SubmitPage' sub to invoke the 'BindData' sub. How
> do I accomplish this? In other words, what parameters do I pass from
> the 'SubmitPage' sub to the 'BindData' sub which the latter expects?
>
Thanks, Teemu...that's exactly what I was looking out for
Teemu Keiski wrote:
> You can't get DataGridItemEventArgs in SubmitPage (it is event argument da
ta
> type specific to a event, so it's not even wise to use as input to a
> method), but you can loop through the DataGrid manually.
> Sub SubmitPage(obj As Object, ea As EventArgs)
>
> For each dgitem As DataGridItem in DataGrid1.Items
> Dim lbl As Label=Nothing
> If (dgitem.ItemType = ListItemType.Item Or dgitem.ItemType =
> ListItemType.AlternatingItem) Then
> lbl = dgitem.FindControl("lblAcre")
> 'Do something with the Label
> End If
> Next
> End Sub
>
> --
> Teemu Keiski
> ASP.NET MVP, AspInsider
> Finland, EU
> http://blogs.aspadvice.com/joteke
> <rn5a@.rediffmail.com> wrote in message
> news:1165068166.263744.157190@.l12g2000cwl.googlegroups.com...

Pass Parameter As DataGridItemEventArgs

A Form has a DataGrid & a Button. The DataGrid's ItemDataBound event
calls a sub named 'BindData'. This sub first finds a Label which exists
in the ItemTemplate of the TemplateColumn of the DataGrid & does some
work with the Label.

Sub BindData(obj As Object, ea As DataGridItemEventArgs)
Dim lbl As Label

If (ea.Item.ItemType = ListItemType.Item Or ea.Item.ItemType =
ListItemType.AlternatingItem) Then
lbl = ea.Item.FindControl("lblAcre")
....
....
End If
End Sub

The Button has the Click event which invokes a sub named 'SubmitPage'.

Sub SubmitPage(obj As Object, ea As EventArgs)
....
End Sub

Now I did like the 'SubmitPage' sub to invoke the 'BindData' sub. How
do I accomplish this? In other words, what parameters do I pass from
the 'SubmitPage' sub to the 'BindData' sub which the latter expects?You can't get DataGridItemEventArgs in SubmitPage (it is event argument data
type specific to a event, so it's not even wise to use as input to a
method), but you can loop through the DataGrid manually.

Sub SubmitPage(obj As Object, ea As EventArgs)

For each dgitem As DataGridItem in DataGrid1.Items

Dim lbl As Label=Nothing

If (dgitem.ItemType = ListItemType.Item Or dgitem.ItemType =
ListItemType.AlternatingItem) Then
lbl = dgitem.FindControl("lblAcre")
'Do something with the Label
End If

Next

End Sub

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke
<rn5a@.rediffmail.comwrote in message
news:1165068166.263744.157190@.l12g2000cwl.googlegr oups.com...

Quote:

Originally Posted by

>A Form has a DataGrid & a Button. The DataGrid's ItemDataBound event
calls a sub named 'BindData'. This sub first finds a Label which exists
in the ItemTemplate of the TemplateColumn of the DataGrid & does some
work with the Label.
>
Sub BindData(obj As Object, ea As DataGridItemEventArgs)
Dim lbl As Label
>
If (ea.Item.ItemType = ListItemType.Item Or ea.Item.ItemType =
ListItemType.AlternatingItem) Then
lbl = ea.Item.FindControl("lblAcre")
....
....
End If
End Sub
>
The Button has the Click event which invokes a sub named 'SubmitPage'.
>
Sub SubmitPage(obj As Object, ea As EventArgs)
....
End Sub
>
Now I did like the 'SubmitPage' sub to invoke the 'BindData' sub. How
do I accomplish this? In other words, what parameters do I pass from
the 'SubmitPage' sub to the 'BindData' sub which the latter expects?
>


Thanks, Teemu...that's exactly what I was looking out for

Teemu Keiski wrote:

Quote:

Originally Posted by

You can't get DataGridItemEventArgs in SubmitPage (it is event argument data
type specific to a event, so it's not even wise to use as input to a
method), but you can loop through the DataGrid manually.
>
Sub SubmitPage(obj As Object, ea As EventArgs)
>
>
For each dgitem As DataGridItem in DataGrid1.Items
>
Dim lbl As Label=Nothing
>
If (dgitem.ItemType = ListItemType.Item Or dgitem.ItemType =
ListItemType.AlternatingItem) Then
lbl = dgitem.FindControl("lblAcre")
'Do something with the Label
End If
>
Next
>
End Sub
>
>
--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke
>
<rn5a@.rediffmail.comwrote in message
news:1165068166.263744.157190@.l12g2000cwl.googlegr oups.com...

Quote:

Originally Posted by

A Form has a DataGrid & a Button. The DataGrid's ItemDataBound event
calls a sub named 'BindData'. This sub first finds a Label which exists
in the ItemTemplate of the TemplateColumn of the DataGrid & does some
work with the Label.

Sub BindData(obj As Object, ea As DataGridItemEventArgs)
Dim lbl As Label

If (ea.Item.ItemType = ListItemType.Item Or ea.Item.ItemType =
ListItemType.AlternatingItem) Then
lbl = ea.Item.FindControl("lblAcre")
....
....
End If
End Sub

The Button has the Click event which invokes a sub named 'SubmitPage'.

Sub SubmitPage(obj As Object, ea As EventArgs)
....
End Sub

Now I did like the 'SubmitPage' sub to invoke the 'BindData' sub. How
do I accomplish this? In other words, what parameters do I pass from
the 'SubmitPage' sub to the 'BindData' sub which the latter expects?

Pass parameter to Popup window

I have 2 webform in vb.NET application.
On Webform1, I have one text box1 and one button.
on Webform2, I have one text box .
I need transfer the value of textbox 1 in webform1 to textbox2 in
webform2. and popup webform2 when user click on the button on webform1.
I have code in webform1:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Button1.Attributes.Add("onclick", "window.open('WebForm2.aspx?a=" +
TextBox1.Text.ToString + "',null,'height=250, width=250,status= no,
resizable= no, scrollbars=no, toolbar=no,location=no,menubar=no ');")
End Sub
and following code in webform2:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
TextBox1.Text = Request("a").ToString
End Sub
I could not get the result unless I click on the button1 twice. i know
what happen in here but have no solution. I will be appreciated if you
could help here.
Thanks in advanced,
DiHi ,
You can achieve this by injecting a javascript in the Button1 click
event on the server side . Write an function to inject an javascript in the
webform1 button1 click.
Don't do anything with Attributes of button1 as it won't achieve result u
requires as the 1st page the textbox1 value would be blank.
private void openWindowInjectScript(){
string myScript;
myScript = "<scr" + "ipt>window.open('WebForm2.aspx?a=" + txtIdfield.Value
+ "',null,'height=250, width=250,status= no,resizable= no, scrollbars=no,
toolbar=no,location=no,menubar=no'); </scr" + "ipt>";
this.Page.RegisterStartupScript("JavaScript",myScript);
}
In the webform1.aspx button1_Click event
private void Button1_Click(object sender, System.EventArgs e)
{
openWindowInjectScript();
}
Basically openwindowInjectScript register a script at pageload and which
will make to open an window with current values.
This is the way out for it and it should work
Regards
IntelYogi
"dyw55a@.yahoo.com" wrote:

> I have 2 webform in vb.NET application.
> On Webform1, I have one text box1 and one button.
> on Webform2, I have one text box .
> I need transfer the value of textbox 1 in webform1 to textbox2 in
> webform2. and popup webform2 when user click on the button on webform1.
> I have code in webform1:
> Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MyBase.Load
> Button1.Attributes.Add("onclick", "window.open('WebForm2.aspx?a=" +
> TextBox1.Text.ToString + "',null,'height=250, width=250,status= no,
> resizable= no, scrollbars=no, toolbar=no,location=no,menubar=no ');")
> End Sub
> and following code in webform2:
> Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MyBase.Load
> TextBox1.Text = Request("a").ToString
> End Sub
>
> I could not get the result unless I click on the button1 twice. i know
> what happen in here but have no solution. I will be appreciated if you
> could help here.
> Thanks in advanced,
> Di
>
Thank you for your reply. But actually I tried and this did not work
for some reason, any idea?
Try this onClick event of your button
Response.Write("<SCRIPT>");
Response.Write("window.open('page,aspx?value=" + myval +
" ',null,'height=200,width=900,status=yes,
toolbar=no,menubar=no,location=no')
;
");
Response.Write("</SCRIPT>");
I think this will do the trick, tell me if not
dyw55a@.yahoo.com wrote in message news:<1117647067.875660.133640@.g43g2000cwa.googlegroups.c
om>...
> Thank you for your reply. But actually I tried and this did not work
> for some reason, any idea?

Pass parameter to Popup window

I have 2 webform in vb.NET application.
On Webform1, I have one text box1 and one button.
on Webform2, I have one text box .
I need transfer the value of textbox 1 in webform1 to textbox2 in
webform2. and popup webform2 when user click on the button on webform1.

I have code in webform1:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Button1.Attributes.Add("onclick", "window.open('WebForm2.aspx?a=" +
TextBox1.Text.ToString + "',null,'height=250, width=250,status= no,
resizable= no, scrollbars=no, toolbar=no,location=no,menubar=no ');")
End Sub

and following code in webform2:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
TextBox1.Text = Request("a").ToString
End Sub

I could not get the result unless I click on the button1 twice. i know
what happen in here but have no solution. I will be appreciated if you
could help here.

Thanks in advanced,
DiHi ,
You can achieve this by injecting a javascript in the Button1 click
event on the server side . Write an function to inject an javascript in the
webform1 button1 click.
Don't do anything with Attributes of button1 as it won't achieve result u
requires as the 1st page the textbox1 value would be blank.

private void openWindowInjectScript(){
string myScript;
myScript = "<scr" + "ipt>window.open('WebForm2.aspx?a=" + txtIdfield.Value
+ "',null,'height=250, width=250,status= no,resizable= no, scrollbars=no,
toolbar=no,location=no,menubar=no'); </scr" + "ipt>";
this.Page.RegisterStartupScript("JavaScript",myScript);
}

In the webform1.aspx button1_Click event
private void Button1_Click(object sender, System.EventArgs e)
{
openWindowInjectScript();
}
Basically openwindowInjectScript register a script at pageload and which
will make to open an window with current values.

This is the way out for it and it should work

Regards
IntelYogi

"dyw55a@.yahoo.com" wrote:

> I have 2 webform in vb.NET application.
> On Webform1, I have one text box1 and one button.
> on Webform2, I have one text box .
> I need transfer the value of textbox 1 in webform1 to textbox2 in
> webform2. and popup webform2 when user click on the button on webform1.
> I have code in webform1:
> Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MyBase.Load
> Button1.Attributes.Add("onclick", "window.open('WebForm2.aspx?a=" +
> TextBox1.Text.ToString + "',null,'height=250, width=250,status= no,
> resizable= no, scrollbars=no, toolbar=no,location=no,menubar=no ');")
> End Sub
> and following code in webform2:
> Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MyBase.Load
> TextBox1.Text = Request("a").ToString
> End Sub
>
> I could not get the result unless I click on the button1 twice. i know
> what happen in here but have no solution. I will be appreciated if you
> could help here.
> Thanks in advanced,
> Di
>
Thank you for your reply. But actually I tried and this did not work
for some reason, any idea?
Try this onClick event of your button

Response.Write("<SCRIPT>");
Response.Write("window.open('page,aspx?value=" + myval +
"',null,'height=200,width=900,status=yes,toolbar=no ,menubar=no,location=no');
");
Response.Write("</SCRIPT>");

I think this will do the trick, tell me if not

dyw55a@.yahoo.com wrote in message news:<1117647067.875660.133640@.g43g2000cwa.googlegroups. com>...
> Thank you for your reply. But actually I tried and this did not work
> for some reason, any idea?
i'd tried both suggest solutions from Yogi, but it seems not work for me...is any solution yet?

the prob is...webform2's page_load will be run 1st b4 the button_click event run...so any wisdom can help up?

From http://www.developmentnow.com/g/8_2...opup-window.htm

Posted via DevelopmentNow.com Groups
http://www.developmentnow.com

Pass Sql Select result to a simple Label.

I'm new and trying to learn. This is in VB.NET 2. I have a simple page
with one Textbox1, one Label1 and one Button1. The on_click Button one goes
and get's a simple data from the SQL db with the parameter from Textbox1.
What do I add to this code below to say that Label1 equals the result of my
Select statement? CroftUser being the result.
Thanks!
Newbie
----------

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim ds As New SqlDataSource()

ds.ConnectionString =
ConfigurationManager.ConnectionStrings("CroftDBConnectionString").ConnectionString

ds.SelectCommandType = SqlDataSourceCommandType.Text

ds.SelectCommand = "Select CroftUser From [User] Where (Password =
@dotnet.itags.org.Password)"

ds.SelectParameters.Add("Password", TextBox1.Text)

End SubPhilip,

If you are trying to populate a control directly via code, I think it is
easier fetch data from the Database using a System.Data.SqlClient.SqlCommand
object instead of the SqlDataSource.

Below is the code for a web page called "SimpleBinding".

Hope this helps,
Jason Vermillion

' alias to the SqlClient namespace
Imports System.Data.SqlClient

Partial Class SandBox_SimpleBindingVB
Inherits System.Web.UI.Page

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim cn As SqlConnection = New SqlConnection()
Dim cmd As SqlCommand = New SqlCommand()
Dim dr As SqlDataReader

Label1.Text = ""

cn.ConnectionString =
ConfigurationManager.ConnectionStrings("CroftDBConnectionString").ConnectionString
cmd.Connection = cn
cmd.CommandText = "Select CroftUser From [User] Where (Password =
@.Password)"
cmd.Parameters.AddWithValue("@.Password", Me.TextBox1.Text)

'Open the connection to the database
cn.Open()
' Execute the sql.
dr = cmd.ExecuteReader()
' Read all of the rows generated by the command (in this case only
one row).
Do While dr.Read()
Label1.Text = dr.Item("CroftUser").ToString()
Loop
' Close your connection to the DB.
dr.Close()
cn.Close()
End Sub
End Class
Jason, thanks SOOO much. That worked perfectly. Can you explain to me why
SqlClient is better in doing this than trying to create a SqlDataSource?

"Jason Vermillion" <JasonVermillion@.discussions.microsoft.comwrote in
message news:9E71D30B-AEF5-4F52-973E-C13501097DDA@.microsoft.com...

Quote:

Originally Posted by

Philip,
>
If you are trying to populate a control directly via code, I think it is
easier fetch data from the Database using a
System.Data.SqlClient.SqlCommand
object instead of the SqlDataSource.
>
Below is the code for a web page called "SimpleBinding".
>
Hope this helps,
Jason Vermillion
>
' alias to the SqlClient namespace
Imports System.Data.SqlClient
>
Partial Class SandBox_SimpleBindingVB
Inherits System.Web.UI.Page
>
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim cn As SqlConnection = New SqlConnection()
Dim cmd As SqlCommand = New SqlCommand()
Dim dr As SqlDataReader
>
Label1.Text = ""
>
cn.ConnectionString =
ConfigurationManager.ConnectionStrings("CroftDBConnectionString").ConnectionString
cmd.Connection = cn
cmd.CommandText = "Select CroftUser From [User] Where (Password =
@.Password)"
cmd.Parameters.AddWithValue("@.Password", Me.TextBox1.Text)
>
'Open the connection to the database
cn.Open()
' Execute the sql.
dr = cmd.ExecuteReader()
' Read all of the rows generated by the command (in this case only
one row).
Do While dr.Read()
Label1.Text = dr.Item("CroftUser").ToString()
Loop
' Close your connection to the DB.
dr.Close()
cn.Close()
End Sub
End Class
>


Phillip,

Quote:

Originally Posted by

Jason, thanks SOOO much. That worked perfectly. Can you explain to me why
SqlClient is better in doing this than trying to create a SqlDataSource?
>


I would not say that using binding with the SqlDataSource is better or
worse, it just depends on what you are trying to do.

When you use a SqlDataSource and bound controls, you get a lot of database
functionality with only a few lines of code and without having to know much
about the way that the underlying Ado.Net works. This is especially true
when working with DataGrids, DataLists, and DataRepeaters. You get paging,
sorting, auto generating columns, and all kinds of other functionality that
would take a long time to code from scratch.

On the flip side, when you use the SqlDataSource (or any of the other data
source controls) you lose flexibility and a bit or performance that you get
when you work directly with the Data.SqlClient objects that are running under
the hood. When you start working with SqlDataSources, I think you'll find
that there are often some cases that come up when you find that the built-in
functionality is not adequate for you what you are trying to accomplish and
you might need to work directly with ado.net (SqlClient, etc.).

I would recommend at least knowing some of the basics of DataSets,
DataTables, DataViews, DataReaders, and DataAdapters.

Here are some links that might be helpful.
Live demos with source code showing hot to use SqlDataSources and Data bound
controls:
http://quickstarts.asp.net/QuickSta...ta/default.aspx
overview of data binding
http://msdn2.microsoft.com/en-us/li...359(VS.80).aspx
ado.net
http://msdn2.microsoft.com/en-us/library/e80y5yhx.aspx
Also, here is some code that just uses SqlDataSources and binding for your
original question. I think the trick was to wrap the User name Label in a
form view control.

Hope this helps,
Jason

Protected Sub cmdGetUserInfo_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles cmdGetUserInfo.Click
SqlDataSource1.Select(DataSourceSelectArguments.Em pty)
End Sub

<asp:TextBox ID="txtPwd" runat="server"></asp:TextBox>
<asp:Button ID="cmdGetUserInfo" runat="server" Text="Button" />
<asp:FormView ID="FormView1" runat="server" DataSourceID="SqlDataSource1">
<ItemTemplate>
<asp:Label ID="lblUserName" runat="server"><%# Eval("CroftUser")
%></asp:Label>
</ItemTemplate>
</asp:FormView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:CroftDBConnectionString %>"
ProviderName="<%$ ConnectionStrings:CroftDBConnectionString.Provider Name %>"
SelectCommand="Select CroftUser From [User] Where (Password = @.Password)">
<SelectParameters>
<asp:ControlParameter ControlID="txtPwd" Name="Password"
PropertyName="Text" />
</SelectParameters>
</asp:SqlDataSource>

Pass Sql Select result to a simple Label.

I'm new and trying to learn. This is in VB.NET 2. I have a simple page
with one Textbox1, one Label1 and one Button1. The on_click Button one goes
and get's a simple data from the SQL db with the parameter from Textbox1.
What do I add to this code below to say that Label1 equals the result of my
Select statement? CroftUser being the result.
Thanks!
Newbie
--
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim ds As New SqlDataSource()
ds.ConnectionString =
ConfigurationManager.ConnectionStrings("CroftDBConnectionString").Connection
String
ds.SelectCommandType = SqlDataSourceCommandType.Text
ds.SelectCommand = "Select CroftUser From [User] Where (Password =
@dotnet.itags.org.Password)"
ds.SelectParameters.Add("Password", TextBox1.Text)
End SubPhilip,
If you are trying to populate a control directly via code, I think it is
easier fetch data from the Database using a System.Data.SqlClient.SqlCommand
object instead of the SqlDataSource.
Below is the code for a web page called "SimpleBinding".
Hope this helps,
Jason Vermillion
' alias to the SqlClient namespace
Imports System.Data.SqlClient
Partial Class SandBox_SimpleBindingVB
Inherits System.Web.UI.Page
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim cn As SqlConnection = New SqlConnection()
Dim cmd As SqlCommand = New SqlCommand()
Dim dr As SqlDataReader
Label1.Text = ""
cn.ConnectionString =
ConfigurationManager.ConnectionStrings("CroftDBConnectionString").Connection
String
cmd.Connection = cn
cmd.CommandText = "Select CroftUser From [User] Where (Password =
@.Password)"
cmd.Parameters.AddWithValue("@.Password", Me.TextBox1.Text)
'Open the connection to the database
cn.Open()
' Execute the sql.
dr = cmd.ExecuteReader()
' Read all of the rows generated by the command (in this case only
one row).
Do While dr.Read()
Label1.Text = dr.Item("CroftUser").ToString()
Loop
' Close your connection to the DB.
dr.Close()
cn.Close()
End Sub
End Class
Jason, thanks SOOO much. That worked perfectly. Can you explain to me why
SqlClient is better in doing this than trying to create a SqlDataSource?
"Jason Vermillion" <JasonVermillion@.discussions.microsoft.com> wrote in
message news:9E71D30B-AEF5-4F52-973E-C13501097DDA@.microsoft.com...
> Philip,
> If you are trying to populate a control directly via code, I think it is
> easier fetch data from the Database using a
> System.Data.SqlClient.SqlCommand
> object instead of the SqlDataSource.
> Below is the code for a web page called "SimpleBinding".
> Hope this helps,
> Jason Vermillion
> ' alias to the SqlClient namespace
> Imports System.Data.SqlClient
> Partial Class SandBox_SimpleBindingVB
> Inherits System.Web.UI.Page
> Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
> System.EventArgs) Handles Button1.Click
> Dim cn As SqlConnection = New SqlConnection()
> Dim cmd As SqlCommand = New SqlCommand()
> Dim dr As SqlDataReader
> Label1.Text = ""
> cn.ConnectionString =
> ConfigurationManager.ConnectionStrings("CroftDBConnectionString").Connecti
onString
> cmd.Connection = cn
> cmd.CommandText = "Select CroftUser From [User] Where (Password =
> @.Password)"
> cmd.Parameters.AddWithValue("@.Password", Me.TextBox1.Text)
> 'Open the connection to the database
> cn.Open()
> ' Execute the sql.
> dr = cmd.ExecuteReader()
> ' Read all of the rows generated by the command (in this case only
> one row).
> Do While dr.Read()
> Label1.Text = dr.Item("CroftUser").ToString()
> Loop
> ' Close your connection to the DB.
> dr.Close()
> cn.Close()
> End Sub
> End Class
>
Phillip,

> Jason, thanks SOOO much. That worked perfectly. Can you explain to me wh
y
> SqlClient is better in doing this than trying to create a SqlDataSource?
>
I would not say that using binding with the SqlDataSource is better or
worse, it just depends on what you are trying to do.
When you use a SqlDataSource and bound controls, you get a lot of database
functionality with only a few lines of code and without having to know much
about the way that the underlying Ado.Net works. This is especially true
when working with DataGrids, DataLists, and DataRepeaters. You get paging,
sorting, auto generating columns, and all kinds of other functionality that
would take a long time to code from scratch.
On the flip side, when you use the SqlDataSource (or any of the other data
source controls) you lose flexibility and a bit or performance that you get
when you work directly with the Data.SqlClient objects that are running unde
r
the hood. When you start working with SqlDataSources, I think you'll find
that there are often some cases that come up when you find that the built-in
functionality is not adequate for you what you are trying to accomplish and
you might need to work directly with ado.net (SqlClient, etc.).
I would recommend at least knowing some of the basics of DataSets,
DataTables, DataViews, DataReaders, and DataAdapters.
Here are some links that might be helpful.
Live demos with source code showing hot to use SqlDataSources and Data bound
controls:
http://quickstarts.asp.net/QuickSta...ibrary/ms178359(VS.80).aspx
ado.net
http://msdn2.microsoft.com/en-us/library/e80y5yhx.aspx
Also, here is some code that just uses SqlDataSources and binding for your
original question. I think the trick was to wrap the User name Label in a
form view control.
Hope this helps,
Jason
Protected Sub cmdGetUserInfo_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles cmdGetUserInfo.Click
SqlDataSource1.Select(DataSourceSelectArguments.Empty)
End Sub
<asp:TextBox ID="txtPwd" runat="server"></asp:TextBox>
<asp:Button ID="cmdGetUserInfo" runat="server" Text="Button" />
<asp:FormView ID="FormView1" runat="server" DataSourceID="SqlDataSource1">
<ItemTemplate>
<asp:Label ID="lblUserName" runat="server"><%# Eval("CroftUser")
%></asp:Label>
</ItemTemplate>
</asp:FormView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:CroftDBConnectionStrin
g %>"
ProviderName="<%$ ConnectionStrings:CroftDBConnectionStrin
g.ProviderName %>"
SelectCommand="Select CroftUser From [User] Where (Password = @.Password)">
<SelectParameters>
<asp:ControlParameter ControlID="txtPwd" Name="Password"
PropertyName="Text" />
</SelectParameters>
</asp:SqlDataSource>

Monday, March 26, 2012

pass text to javascript function

Hello,
I found this code and I want to pass this function a value
from a dataset.

How do I do this?

<INPUT onmouseover="func()" type="button" value="Button"
<script type=text/javascript>
function func()
{
//you could put anything here, e.g. opening a window etc.
alert('Hi');
}
</script<INPUT runat="server" id="myButton" onmouseover="func()" type="button"
value="Button"
In the code behind (C#):

myButton.Attributes["onmouseover"]=String.Format("func({0})", "my text");

Eliyahu

"prav" <prav@.hotmail.com> wrote in message
news:10ca01c4d624$ae4a5410$a501280a@.phx.gbl...
> Hello,
> I found this code and I want to pass this function a value
> from a dataset.
> How do I do this?
> <INPUT onmouseover="func()" type="button" value="Button">
>
> <script type=text/javascript>
> function func()
> {
> //you could put anything here, e.g. opening a window etc.
> alert('Hi');
> }
> </script>
Eliyahu Goldin wrote:
> <INPUT runat="server" id="myButton" onmouseover="func()"
> type="button" value="Button">
> In the code behind (C#):
> myButton.Attributes["onmouseover"]=String.Format("func({0})", "my
> text");
> Eliyahu

You might want to put quotes around that text:

String.Format("func('{0}')", "my text");

(and then you could still have problems with quotes inside the string)

Hans Kesting

pass text to javascript function

Hello,
I found this code and I want to pass this function a value
from a dataset.
How do I do this?
<INPUT onmouseover="func()" type="button" value="Button">
<script type=text/javascript>
function func()
{
//you could put anything here, e.g. opening a window etc.
alert('Hi');
}
</script><INPUT runat="server" id="myButton" onmouseover="func()" type="button"
value="Button">
In the code behind (C#):
myButton.Attributes["onmouseover"]=String.Format("func({0})", "my text");
Eliyahu
"prav" <prav@.hotmail.com> wrote in message
news:10ca01c4d624$ae4a5410$a501280a@.phx.gbl...
> Hello,
> I found this code and I want to pass this function a value
> from a dataset.
> How do I do this?
> <INPUT onmouseover="func()" type="button" value="Button">
>
> <script type=text/javascript>
> function func()
> {
> //you could put anything here, e.g. opening a window etc.
> alert('Hi');
> }
> </script>
>
Eliyahu Goldin wrote:
> <INPUT runat="server" id="myButton" onmouseover="func()"
> type="button" value="Button">
> In the code behind (C#):
> myButton.Attributes["onmouseover"]=String.Format("func({0})", "my
> text");
> Eliyahu
>
You might want to put quotes around that text:
String.Format("func('{0}')", "my text");
(and then you could still have problems with quotes inside the string)
Hans Kesting

pass the arguments from web to windows

Hi all,
I have created one web applicatication which contains button.When I
click the button
I want to pass arguments to windows application.Can I do it?Any one
please help me...
Regards justinHi,
How about this code:

string strArg = @." the arguments comes here";

process.StartInfo.Arguments = strArg;

process.StartInfo.UseShellExecute = false;

process.StartInfo.RedirectStandardOutput = true;

try

{

process.Start();

}

catch(Exception ex)

{

string str = ex.Source + ex.Message + ex.StackTrace;

}

Thanks and Regards,
Manish Bafna.
MCP and MCTS.

"justin" wrote:

Quote:

Originally Posted by

Hi all,
I have created one web applicatication which contains button.When I
click the button
I want to pass arguments to windows application.Can I do it?Any one
please help me...
Regards justin
>
>


The simplest (or one of the simplest) way of communicating between
applications is via text files. One guy writes, another reads.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]

"justin" <justindhasy@.gmail.comwrote in message
news:1166424002.419061.231640@.j72g2000cwa.googlegr oups.com...

Quote:

Originally Posted by

Hi all,
I have created one web applicatication which contains button.When I
click the button
I want to pass arguments to windows application.Can I do it?Any one
please help me...
Regards justin
>

pass the arguments from web to windows

Hi all,
I have created one web applicatication which contains button.When I
click the button
I want to pass arguments to windows application.Can I do it?Any one
please help me...
Regards justinHi,
How about this code:
string strArg = @." the arguments comes here";
process.StartInfo.Arguments = strArg;
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
try
{
process.Start();
}
catch(Exception ex)
{
string str = ex.Source + ex.Message + ex.StackTrace;
}
Thanks and Regards,
Manish Bafna.
MCP and MCTS.
"justin" wrote:

> Hi all,
> I have created one web applicatication which contains button.When I
> click the button
> I want to pass arguments to windows application.Can I do it?Any one
> please help me...
> Regards justin
>
The simplest (or one of the simplest) way of communicating between
applications is via text files. One guy writes, another reads.
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
"justin" <justindhasy@.gmail.com> wrote in message
news:1166424002.419061.231640@.j72g2000cwa.googlegroups.com...
> Hi all,
> I have created one web applicatication which contains button.When I
> click the button
> I want to pass arguments to windows application.Can I do it?Any one
> please help me...
> Regards justin
>

Saturday, March 24, 2012

Pass variables value between diferent pages

Hi,
How can I pass the values of some variables from page1.aspx to page2.aspx?
I try to define some variables in page2 and then when I click a button in
page1 it will fill that variables (in page2) with values. The proble is that
when I call page2 variable values are NULL.

Like this:

----------BEGIN
CODE---------------

Imports AppName.ClassNamePage2

Dim m_Page2 as New ClassNamePage2

Private Sub Button1_ServerClick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.ServerClick

//This values are in a DataSet and are correct (I debug them)

m_Page2.m_lIdHrq = CLng(ds.Tables("Dados").Rows(0).Item("IdLevel"))
m_Page2.m_lNivelHrq = CLng(ds.Tables("Dados").Rows(0).Item("Level"))
m_Page2.m_strFnc = CStr(ds.Tables("Dados").Rows(0).Item("Name"))

//this value it is given from a dropdownlist (I check it, and it returns
the right value)
m_Page2.m_lIdFnc = CLng(UserName.SelectedItem.Value.ToString())

Response.Redirect("Page2.aspx")

//When opens page2.aspx the values are NULL

End Sub
----------END
CODE---------------

How can I solve this?

--

Thank's (if you try to help me)
Hope this help you (if I try to help you)
rucaSince you are redirecting then the easiest way is to send them as parameters
(Querystrings)

response.redirect("Page2.aspx?m_lIdHrq="& m_Page2.m_lIdHrq &"&m_lNivelHrq="&
m_Page2.m_lNivelHrq &"&m_strFnc="& m_Page2.m_strFnc)

or you can use Session variables.

regards,
--
Sarmad Aljazrawi
B.Sc. Computer Science, MSDBA, MCP
www.aljazrawi.net

"ruca" <ruuca@.iol.pt> wrote in message
news:OXzXtNF$DHA.2808@.TK2MSFTNGP10.phx.gbl...
> Hi,
> How can I pass the values of some variables from page1.aspx to page2.aspx?
> I try to define some variables in page2 and then when I click a button in
> page1 it will fill that variables (in page2) with values. The proble is
that
> when I call page2 variable values are NULL.
> Like this:
> ----------BEGIN
> CODE---------------
> Imports AppName.ClassNamePage2
> Dim m_Page2 as New ClassNamePage2
> Private Sub Button1_ServerClick(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles Button1.ServerClick
> //This values are in a DataSet and are correct (I debug them)
> m_Page2.m_lIdHrq = CLng(ds.Tables("Dados").Rows(0).Item("IdLevel"))
> m_Page2.m_lNivelHrq = CLng(ds.Tables("Dados").Rows(0).Item("Level"))
> m_Page2.m_strFnc = CStr(ds.Tables("Dados").Rows(0).Item("Name"))
> //this value it is given from a dropdownlist (I check it, and it
returns
> the right value)
> m_Page2.m_lIdFnc = CLng(UserName.SelectedItem.Value.ToString())
> Response.Redirect("Page2.aspx")
> //When opens page2.aspx the values are NULL
> End Sub
> ----------END
> CODE---------------
> How can I solve this?
>
> --
> Thank's (if you try to help me)
> Hope this help you (if I try to help you)
> ruca
I like it more of your second option. Can you give me an example of that. I
presume that I have to set this variables in my GlobaAsa file, right?

--

Thank's (if you try to help me)
Hope this help you (if I try to help you)
ruca

"Sarmad Aljazrawi" <anonymous[shylme]@.discussions.microsoft.com> escreveu na
mensagem news:eH9fe0F$DHA.1732@.TK2MSFTNGP12.phx.gbl...
> Since you are redirecting then the easiest way is to send them as
parameters
> (Querystrings)
> response.redirect("Page2.aspx?m_lIdHrq="& m_Page2.m_lIdHrq
&"&m_lNivelHrq="&
> m_Page2.m_lNivelHrq &"&m_strFnc="& m_Page2.m_strFnc)
> or you can use Session variables.
> regards,
> --
> Sarmad Aljazrawi
> B.Sc. Computer Science, MSDBA, MCP
> www.aljazrawi.net
>
> "ruca" <ruuca@.iol.pt> wrote in message
> news:OXzXtNF$DHA.2808@.TK2MSFTNGP10.phx.gbl...
> > Hi,
> > How can I pass the values of some variables from page1.aspx to
page2.aspx?
> > I try to define some variables in page2 and then when I click a button
in
> > page1 it will fill that variables (in page2) with values. The proble is
> that
> > when I call page2 variable values are NULL.
> > Like this:
> > ----------BEGIN
> > CODE---------------
> > Imports AppName.ClassNamePage2
> > Dim m_Page2 as New ClassNamePage2
> > Private Sub Button1_ServerClick(ByVal sender As System.Object, ByVal e
As
> > System.EventArgs) Handles Button1.ServerClick
> > //This values are in a DataSet and are correct (I debug them)
> > m_Page2.m_lIdHrq = CLng(ds.Tables("Dados").Rows(0).Item("IdLevel"))
> > m_Page2.m_lNivelHrq = CLng(ds.Tables("Dados").Rows(0).Item("Level"))
> > m_Page2.m_strFnc = CStr(ds.Tables("Dados").Rows(0).Item("Name"))
> > //this value it is given from a dropdownlist (I check it, and it
> returns
> > the right value)
> > m_Page2.m_lIdFnc = CLng(UserName.SelectedItem.Value.ToString())
> > Response.Redirect("Page2.aspx")
> > //When opens page2.aspx the values are NULL
> > End Sub
> > ----------END
> > CODE---------------
> > How can I solve this?
> > --
> > Thank's (if you try to help me)
> > Hope this help you (if I try to help you)
> > ruca
unless you want to store the variables on an sql server or work cookieless
you don't have to do anithing special

session.add("VarName",Value)
value = session.item("VarName")

hope it helps

eric

"ruca" <ruuca@.iol.pt> wrote in message
news:O9ycx6F$DHA.2576@.tk2msftngp13.phx.gbl...
> I like it more of your second option. Can you give me an example of that.
I
> presume that I have to set this variables in my GlobaAsa file, right?
>
> --
> Thank's (if you try to help me)
> Hope this help you (if I try to help you)
> ruca
> "Sarmad Aljazrawi" <anonymous[shylme]@.discussions.microsoft.com> escreveu
na
> mensagem news:eH9fe0F$DHA.1732@.TK2MSFTNGP12.phx.gbl...
> > Since you are redirecting then the easiest way is to send them as
> parameters
> > (Querystrings)
> > response.redirect("Page2.aspx?m_lIdHrq="& m_Page2.m_lIdHrq
> &"&m_lNivelHrq="&
> > m_Page2.m_lNivelHrq &"&m_strFnc="& m_Page2.m_strFnc)
> > or you can use Session variables.
> > regards,
> > --
> > Sarmad Aljazrawi
> > B.Sc. Computer Science, MSDBA, MCP
> > www.aljazrawi.net
> > "ruca" <ruuca@.iol.pt> wrote in message
> > news:OXzXtNF$DHA.2808@.TK2MSFTNGP10.phx.gbl...
> > > Hi,
> > > How can I pass the values of some variables from page1.aspx to
> page2.aspx?
> > > I try to define some variables in page2 and then when I click a button
> in
> > > page1 it will fill that variables (in page2) with values. The proble
is
> > that
> > > when I call page2 variable values are NULL.
> > > > Like this:
> > > > ----------BEGIN
> > > CODE---------------
> > > > Imports AppName.ClassNamePage2
> > > > Dim m_Page2 as New ClassNamePage2
> > > > Private Sub Button1_ServerClick(ByVal sender As System.Object, ByVal e
> As
> > > System.EventArgs) Handles Button1.ServerClick
> > > > //This values are in a DataSet and are correct (I debug them)
> > > > m_Page2.m_lIdHrq =
CLng(ds.Tables("Dados").Rows(0).Item("IdLevel"))
> > > m_Page2.m_lNivelHrq =
CLng(ds.Tables("Dados").Rows(0).Item("Level"))
> > > m_Page2.m_strFnc = CStr(ds.Tables("Dados").Rows(0).Item("Name"))
> > > > //this value it is given from a dropdownlist (I check it, and it
> > returns
> > > the right value)
> > > m_Page2.m_lIdFnc = CLng(UserName.SelectedItem.Value.ToString())
> > > > Response.Redirect("Page2.aspx")
> > > > //When opens page2.aspx the values are NULL
> > > > End Sub
> > > ----------END
> > > CODE---------------
> > > > How can I solve this?
> > > > > --
> > > > Thank's (if you try to help me)
> > > Hope this help you (if I try to help you)
> > > ruca
> >
No you don't need to set it up in global.asa you can set it any place in the
application.

session("myvar") = value
value = session("myvar")

--
Sarmad Aljazrawi
B.Sc. Computer Science, MSDBA, MCP
www.aljazrawi.net

"ruca" <ruuca@.iol.pt> wrote in message
news:O9ycx6F$DHA.2576@.tk2msftngp13.phx.gbl...
> I like it more of your second option. Can you give me an example of that.
I
> presume that I have to set this variables in my GlobaAsa file, right?
>
> --
> Thank's (if you try to help me)
> Hope this help you (if I try to help you)
> ruca
> "Sarmad Aljazrawi" <anonymous[shylme]@.discussions.microsoft.com> escreveu
na
> mensagem news:eH9fe0F$DHA.1732@.TK2MSFTNGP12.phx.gbl...
> > Since you are redirecting then the easiest way is to send them as
> parameters
> > (Querystrings)
> > response.redirect("Page2.aspx?m_lIdHrq="& m_Page2.m_lIdHrq
> &"&m_lNivelHrq="&
> > m_Page2.m_lNivelHrq &"&m_strFnc="& m_Page2.m_strFnc)
> > or you can use Session variables.
> > regards,
> > --
> > Sarmad Aljazrawi
> > B.Sc. Computer Science, MSDBA, MCP
> > www.aljazrawi.net
> > "ruca" <ruuca@.iol.pt> wrote in message
> > news:OXzXtNF$DHA.2808@.TK2MSFTNGP10.phx.gbl...
> > > Hi,
> > > How can I pass the values of some variables from page1.aspx to
> page2.aspx?
> > > I try to define some variables in page2 and then when I click a button
> in
> > > page1 it will fill that variables (in page2) with values. The proble
is
> > that
> > > when I call page2 variable values are NULL.
> > > > Like this:
> > > > ----------BEGIN
> > > CODE---------------
> > > > Imports AppName.ClassNamePage2
> > > > Dim m_Page2 as New ClassNamePage2
> > > > Private Sub Button1_ServerClick(ByVal sender As System.Object, ByVal e
> As
> > > System.EventArgs) Handles Button1.ServerClick
> > > > //This values are in a DataSet and are correct (I debug them)
> > > > m_Page2.m_lIdHrq =
CLng(ds.Tables("Dados").Rows(0).Item("IdLevel"))
> > > m_Page2.m_lNivelHrq =
CLng(ds.Tables("Dados").Rows(0).Item("Level"))
> > > m_Page2.m_strFnc = CStr(ds.Tables("Dados").Rows(0).Item("Name"))
> > > > //this value it is given from a dropdownlist (I check it, and it
> > returns
> > > the right value)
> > > m_Page2.m_lIdFnc = CLng(UserName.SelectedItem.Value.ToString())
> > > > Response.Redirect("Page2.aspx")
> > > > //When opens page2.aspx the values are NULL
> > > > End Sub
> > > ----------END
> > > CODE---------------
> > > > How can I solve this?
> > > > > --
> > > > Thank's (if you try to help me)
> > > Hope this help you (if I try to help you)
> > > ruca
> >

Wednesday, March 21, 2012

passing a Guid to a button class

Hi i have a linkbutton created with C# that needs to call a class and pass a guid through to that class i have tried to use

public void buttonClass(string guid,object sender,Eventargs e)
but it does work i get an error so how do i pass a guid to this class form my button ( code below)

1//button class2public void prodAdd(object sender, EventArgs e)3 {4 checkoutFunctions cartAdd =new checkoutFunctions();5string userGuid = cartAdd.userFind(HttpContext.Current.User.Identity.Name);6 cartAdd.addItem(prodGuid, userGuid);7 Response.Redirect("cart.aspx");8 }910// BUtton generator11 mediaSelect.Controls.Add(new LiteralControl("<a href='#' onClick=\"flashshowHide('" + mediaId + "')\">" + medRead["media_name"].ToString().Replace("#@dotnet.itags.org.","'") +"<span class='prevBut'>(preview)</span></a>"));12 Button buyProd =new Button();13 buyProd.Text = ("Download for £" + medRead["media_price"].ToString());14 buyProd.Click +=new EventHandler(prodAdd);15 mediaSelect.Controls.Add(buyProd);16 mediaSelect.Controls.Add(new LiteralControl("<br/>"));
Thanks
Dan 

I think you must be missing something here conceptually. The prodAdd isnt a button class, it's an event handler that you're wiring up to handle the click event of your dynamically created button. That set of code will run only when the button is clicked. If you need to pass a GUID to it, pass it from wherever it was clicked at, not when the button is created.


yes ok but how do i set it to send the guid to the class when it is clicked


It's not a class - it's an event handler. You are going to have issues till you can get your terminology correct.

Try

buyProd.commandArgument = yourGUID

then in your event handler you can get the guid by using

e.commandArgument

Passing a Querry string in a Response.Redirect?

I want to be able to redirect on a Button click event with a querry string attached with the username, is this possible?
would it look something like?
'Response.Redirect("link.aspx?UserId="Label.Text"") or
'Response.Redirect("link.aspx?userid=("Label.Text"))

This should do it:
Response.Redirect( "link.aspx?UserId=" & Server.UrlEncode(myLabel.Text) )

Friday, March 16, 2012

passing a value to an event handler from dropdownlist

I've got a command button to submit a value from a dropdown list that should
then filter a SELECT query. I'm simply appending a WHERE colx =
<variableSelectedFromDropdownList>. How do I pass this value into the event
handler?

-- MY EVENT HANDLER

Sub RunReport_OnClick(sender As Object, e As System.EventArgs)

_sqlStmt = _sqlStmt & " AND colx = '<variableSelectedFromDropdownList>'"
BindData()

End Sub

-- ON MY WEB FORM
<ASP:Button id="cmdRunReport" Text="Run Report" runat="server"
onclick="RunReport_OnClick" /
<ASP:dropdownlist id="Provinces" runat="server" Font-Size="8pt"
Width="100px"></ASP:dropdownlist
-- MY DATA ACCESS CODE

Sub BindData()
Dim conString As String = "server=server;database=db;uid=un;pwd=pwd;"
Dim myDataSet1 As New DataSet
Dim myDataAdapter1 As New SqlDataAdapter(_sqlStmt, conString)
myDataAdapter1.Fill(myDataSet1, "Communities")
DataGrid2.DataSource = myDataSet1.Tables("Communities")

Dim myDataSet2 As New DataSet
Dim myDataAdapter2 As New SqlDataAdapter(_sqlStmt2, conString)
myDataAdapter2.Fill(myDataSet2, "ProvincesT")
Provinces.Datasource = myDataSet2.Tables("ProvincesT")
Provinces.DataMember = "ProvincesT"
Provinces.DataTextField = "clnName"
Provinces.DataValueField = "clnGUID"

DataGrid2.DataBind()
Provinces.DataBind()

End Sub

_____
DC GChange the following
_sqlStmt = _sqlStmt & " AND colx = '<variableSelectedFromDropdownList>'
t
_sqlStmt = _sqlStmt & " AND colx = '" & mydropdownlist.SelectedItem.Value & "'
'your data access code will go her
BindData(

HTH
Suresh

p.s. Sorry i couldn't help you with "Datagrid won't sort" problem. If you still haven't figured it out please create another message for your problem on this NG

-- DC Gringo wrote: --

I've got a command button to submit a value from a dropdown list that shoul
then filter a SELECT query. I'm simply appending a WHERE colx
<variableSelectedFromDropdownList>. How do I pass this value into the even
handler

-- MY EVENT HANDLE

Sub RunReport_OnClick(sender As Object, e As System.EventArgs

_sqlStmt = _sqlStmt & " AND colx = '<variableSelectedFromDropdownList>'
BindData(

End Su

-- ON MY WEB FOR
<ASP:Button id="cmdRunReport" Text="Run Report" runat="server
onclick="RunReport_OnClick" /><ASP:dropdownlist id="Provinces" runat="server" Font-Size="8pt
Width="100px"></ASP:dropdownlist

-- MY DATA ACCESS COD

Sub BindData(
Dim conString As String = "server=server;database=db;uid=un;pwd=pwd;
Dim myDataSet1 As New DataSe
Dim myDataAdapter1 As New SqlDataAdapter(_sqlStmt, conString
myDataAdapter1.Fill(myDataSet1, "Communities"
DataGrid2.DataSource = myDataSet1.Tables("Communities"

Dim myDataSet2 As New DataSe
Dim myDataAdapter2 As New SqlDataAdapter(_sqlStmt2, conString
myDataAdapter2.Fill(myDataSet2, "ProvincesT"
Provinces.Datasource = myDataSet2.Tables("ProvincesT"
Provinces.DataMember = "ProvincesT
Provinces.DataTextField = "clnName
Provinces.DataValueField = "clnGUID

DataGrid2.DataBind(
Provinces.DataBind(

End Su

____
DC
Yes, that got rid of my error...but the results are only the first record in
the table everytime...and doesn't match the filter criteria...

_____
DC G

"Suresh" <anonymous@.discussions.microsoft.com> wrote in message
news:1284065D-1C70-46C7-B8E6-17C16AFB481C@.microsoft.com...
> Change the following
> _sqlStmt = _sqlStmt & " AND colx = '<variableSelectedFromDropdownList>'"
> to
> _sqlStmt = _sqlStmt & " AND colx = '" & mydropdownlist.SelectedItem.Value
& "'"
> 'your data access code will go here
> BindData()
> HTH,
> Suresh.
> p.s. Sorry i couldn't help you with "Datagrid won't sort" problem. If you
still haven't figured it out please create another message for your problem
on this NG.
>
> -- DC Gringo wrote: --
> I've got a command button to submit a value from a dropdown list that
should
> then filter a SELECT query. I'm simply appending a WHERE colx =
> <variableSelectedFromDropdownList>. How do I pass this value into
the event
> handler?
> -- MY EVENT HANDLER
> Sub RunReport_OnClick(sender As Object, e As System.EventArgs)
> _sqlStmt = _sqlStmt & " AND colx =
'<variableSelectedFromDropdownList>'"
> BindData()
>
> End Sub
> -- ON MY WEB FORM
> <ASP:Button id="cmdRunReport" Text="Run Report" runat="server"
> onclick="RunReport_OnClick" /><ASP:dropdownlist id="Provinces"
runat="server" Font-Size="8pt"
> Width="100px"></ASP:dropdownlist>
>
> -- MY DATA ACCESS CODE
> Sub BindData()
> Dim conString As String =
"server=server;database=db;uid=un;pwd=pwd;"
> Dim myDataSet1 As New DataSet
> Dim myDataAdapter1 As New SqlDataAdapter(_sqlStmt, conString)
> myDataAdapter1.Fill(myDataSet1, "Communities")
> DataGrid2.DataSource = myDataSet1.Tables("Communities")
> Dim myDataSet2 As New DataSet
> Dim myDataAdapter2 As New SqlDataAdapter(_sqlStmt2,
conString)
> myDataAdapter2.Fill(myDataSet2, "ProvincesT")
> Provinces.Datasource = myDataSet2.Tables("ProvincesT")
> Provinces.DataMember = "ProvincesT"
> Provinces.DataTextField = "clnName"
> Provinces.DataValueField = "clnGUID"
>
> DataGrid2.DataBind()
> Provinces.DataBind()
> End Sub
>
> _____
> DC G
What's your _sqlStmt

Can you also post your Data access code

Suresh

-- DC Gringo wrote: --

Yes, that got rid of my error...but the results are only the first record i
the table everytime...and doesn't match the filter criteria...

____
DC

"Suresh" <anonymous@.discussions.microsoft.com> wrote in messag
news:1284065D-1C70-46C7-B8E6-17C16AFB481C@.microsoft.com..
> Change the followin
> _sqlStmt = _sqlStmt & " AND colx = '<variableSelectedFromDropdownList>'
> t
> _sqlStmt = _sqlStmt & " AND colx = '" & mydropdownlist.SelectedItem.Valu
& "'
> 'your data access code will go her
> BindData(
>> HTH
> Suresh
>> p.s. Sorry i couldn't help you with "Datagrid won't sort" problem. If yo
still haven't figured it out please create another message for your proble
on this NG
>>> -- DC Gringo wrote: --
>> I've got a command button to submit a value from a dropdown list tha
shoul
> then filter a SELECT query. I'm simply appending a WHERE colx
><variableSelectedFromDropdownList>. How do I pass this value int
the even
> handler
>> -- MY EVENT HANDLE
>> Sub RunReport_OnClick(sender As Object, e As System.EventArgs
>> _sqlStmt = _sqlStmt & " AND colx
'<variableSelectedFromDropdownList>'
> BindData(
>>> End Su
>> -- ON MY WEB FOR
><ASP:Button id="cmdRunReport" Text="Run Report" runat="server
> onclick="RunReport_OnClick" /><ASP:dropdownlist id="Provinces
runat="server" Font-Size="8pt
> Width="100px"></ASP:dropdownlist>>>> -- MY DATA ACCESS COD
>> Sub BindData(
> Dim conString As String
"server=server;database=db;uid=un;pwd=pwd;
> Dim myDataSet1 As New DataSe
> Dim myDataAdapter1 As New SqlDataAdapter(_sqlStmt, conString
> myDataAdapter1.Fill(myDataSet1, "Communities"
> DataGrid2.DataSource = myDataSet1.Tables("Communities"
>> Dim myDataSet2 As New DataSe
> Dim myDataAdapter2 As New SqlDataAdapter(_sqlStmt2
conString
> myDataAdapter2.Fill(myDataSet2, "ProvincesT"
> Provinces.Datasource = myDataSet2.Tables("ProvincesT"
> Provinces.DataMember = "ProvincesT
> Provinces.DataTextField = "clnName
> Provinces.DataValueField = "clnGUID
>>> DataGrid2.DataBind(
> Provinces.DataBind(
>> End Su
>>> ____
> DC
>>>
Suresh, here's the whole thing:

<%@. Import Namespace="System.Data" %>
<%@. Import Namespace="System.Data.SqlClient" %>
<%@. Import Namespace="System.Web.UI.WebControls" %>
<%@. Import Namespace="System.Web.UI.WebControls.DropDownList" %
<%@. Page Language="VB" Debug="true" %>
<script runat="server" language="VB"
Protected _sqlStmt As String = _
"SELECT c1.clnName as Community, s1.clnGUID, s1.clnPriorityCorrectedTC as
Impact, PopulationKeyInfo = ISNULL(s1.clnPopulationKeyInfo,0),
MinedAreaVictimCount = ISNULL(mavc1.MinedAreaVictimCount,0), nonRecentVictim
= ISNULL(s1.clnVictimOldKilled + s1.clnVictimOldInjured, 0), SHACount =
ISNULL(mavc1.SHACount,0), clnEconomicBaseTC =
ISNULL(s1.clnEconomicBaseTC,'None specified'), MinDistance =
ISNULL(sha1.MinDistance, 0), VictimAssist = ISNULL(mavc1.VictimAssist,
'No'), clnMADoneTC = ISNULL(s1.clnMADoneTC,'Unknown') FROM tblSurvey1 s1
INNER JOIN tblCity c1 ON s1.clnNearestCityGUID = c1.clnGUID INNER JOIN
vwMinDistancesToNearestSHA sha1 ON s1.clnGUID = sha1.clnSurveyGUID LEFT
OUTER JOIN vwMinedAreaVictimCount mavc1 ON s1.clnGUID = mavc1.clnGUID WHERE
s1.clnPriorityCorrectedTC <> 'None'"

Protected _sqlStmt5 As String = _
"SELECT c1.clnName, s1.clnGUID FROM tblSurvey1 s1 INNER JOIN tblCity c1 ON
s1.clnNearestCityGUID = c1.clnGUID ORDER BY c1.clnName"

'Protected WithEvents ddlCommunities As
System.Web.UI.WebControls.DropDownList

Sub Page_Load(Source As Object, E As EventArgs)
'If Not Page.IsPostBack Then
BindData()
'End If
End Sub

Sub BindData()
Dim conString As String = "server=server;database=db;uid=user;pwd=pwd;"
Dim myDataSet1 As New DataSet
Dim myDataAdapter1 As New SqlDataAdapter(_sqlStmt, conString)
myDataAdapter1.Fill(myDataSet1, "CommunitiesT1")
DataGrid2.DataSource = myDataSet1.Tables("CommunitiesT1")

Dim myDataSet5 As New DataSet
Dim myDataAdapter5 As New SqlDataAdapter(_sqlStmt5, conString)
myDataAdapter5.Fill(myDataSet5, "CommunitiesT2")
ddlCommunities.DataSource = myDataSet5.Tables("CommunitiesT2")
ddlCommunities.DataMember = "CommunitiesT2"
ddlCommunities.DataTextField = "clnName"
ddlCommunities.DataValueField = "clnGUID"

DataGrid2.DataBind()
ddlCommunities.DataBind()

End Sub

Sub SortCommand_OnClick(Source As Object, E As
DataGridSortCommandEventArgs)
_sqlStmt = _sqlStmt & " ORDER BY " & E.SortExpression
BindData()
End Sub

Sub PageIndexChanged_OnClick(Source As Object, E As
DataGridPageChangedEventArgs)
DataGrid2.CurrentPageIndex = E.NewPageIndex
BindData()
End Sub

Sub RunReport_OnClick(sender As Object, e As System.EventArgs)

_sqlStmt = _sqlStmt & " AND s1.clnGUID =
'"+ddlCommunities.SelectedItem.Value+"'"

BindData()

End Sub

</script
<html>
<head>
<title></title
<style>
.DataGrid {font:x-small Verdana, Arial, sans-serif}
</style>
<LINK rel="stylesheet" href="http://links.10026.com/?link=../Styles.css" type="text/css">
</head>
<body
<asp:dropdownlist Font-Size="8" id="ddlCommunities" runat="server"
Width="100"></asp:dropdownlist></td
<ASP:Button id="cmdRunReport" Text="Run Report" runat="server"
onclick="RunReport_OnClick" /
<asp:DataGrid
AllowCustomPaging="false"
AllowPaging="true"
AllowSorting="true"
AlternatingItemStyle-BackColor="#EFEFEF"
AutoGenerateColumns="false"
Border="0"
Cellpadding="4"
Cellspacing="0"
CssClass="DataGrid"
DataKeyField="clnGUID"
Enabled="true"
EnableViewState="true"
HeaderStyle-BackColor="Black"
HeaderStyle-Font-Bold="True"
HeaderStyle-ForeColor="White" id="DataGrid2" runat="server"
ShowFooter="false"
OnSortCommand="SortCommand_OnClick"
OnPageIndexChanged="PageIndexChanged_OnClick"
PageSize="50"
PagerStyle-Mode="NumericPages"
PagerStyle-HorizontalAlign="Right"
ShowHeader="true"

<SelectedItemStyle Font-Bold="True" ForeColor="#663399"
BackColor="#FFCC66"></SelectedItemStyle>
<ItemStyle Font-Size="8pt" Font-Names="Verdana" ForeColor="#330099"
BackColor="White"></ItemStyle>
<HeaderStyle Font-Size="8pt" Font-Names="Verdana" Font-Bold="True"
HorizontalAlign="Center" ForeColor="#FFFFCC"
BackColor="#990000"></HeaderStyle>
<FooterStyle ForeColor="#330099" BackColor="#FFFFCC"></FooterStyle
<Columns>
<asp:HyperLinkColumn DataNavigateUrlField="Community"
DataNavigateUrlFormatString="clnGUID" DataTextField="Community"
Visible="true" NavigateUrl="http://{cgi.server_name}/c={clnGUID}"
SortExpression="Community"
HeaderText="Community" text="Community" runat="server">
<HeaderStyle HorizontalAlign="Left"></HeaderStyle>
<ItemStyle HorizontalAlign="Left"></ItemStyle>
</asp:HyperLinkColumn>
<asp:BoundColumn DataField="Impact" SortExpression="Impact"
HeaderText="Impact"></asp:BoundColumn>
<asp:BoundColumn DataField="PopulationKeyInfo"
SortExpression="PopulationKeyInfo" HeaderText="Population<br>Key
Info"></asp:BoundColumn>
<asp:BoundColumn DataField="MinedAreaVictimCount"
SortExpression="MinedAreaVictimCount"
HeaderText="Recent<br>Victims"></asp:BoundColumn>
<asp:BoundColumn DataField="SHACount" SortExpression="SHACount"
HeaderText="No. of<br>SHA's"></asp:BoundColumn>
<asp:BoundColumn DataField="clnEconomicBaseTC"
SortExpression="clnEconomicBaseTC"
HeaderText="Economic<br>Base"></asp:BoundColumn>
<asp:BoundColumn DataField="clnMADoneTC" SortExpression="clnMADoneTC"
HeaderText="Mine Risk<br>Education"></asp:BoundColumn>
<asp:BoundColumn DataField="VictimAssist" SortExpression="VictimAssist"
HeaderText="Victim<br>Assist"></asp:BoundColumn>
<asp:BoundColumn DataField="MinDistance" SortExpression="MinDistance"
HeaderText="Min Distance<br>to SHA"></asp:BoundColumn>
</columns>
<PagerStyle HorizontalAlign="Center" ForeColor="#330099"
Position="TopAndBottom" BackColor="#FFFFCC"
Mode="NumericPages"></PagerStyle>
</asp:DataGrid
</form>
</body>
</html>
"Suresh" <anonymous@.discussions.microsoft.com> wrote in message
news:6EE07FEA-BD32-44E2-AB30-C0A814C040F2@.microsoft.com...
> What's your _sqlStmt?
> Can you also post your Data access code?
> Suresh.
> -- DC Gringo wrote: --
> Yes, that got rid of my error...but the results are only the first
record in
> the table everytime...and doesn't match the filter criteria...
> _____
> DC G
>
> "Suresh" <anonymous@.discussions.microsoft.com> wrote in message
> news:1284065D-1C70-46C7-B8E6-17C16AFB481C@.microsoft.com...
> > Change the following
> > _sqlStmt = _sqlStmt & " AND colx =
'<variableSelectedFromDropdownList>'"
> > to
> > _sqlStmt = _sqlStmt & " AND colx = '" &
mydropdownlist.SelectedItem.Value
> & "'"
> > 'your data access code will go here
> > BindData()
> >> HTH,
> > Suresh.
> >> p.s. Sorry i couldn't help you with "Datagrid won't sort" problem.
If you
> still haven't figured it out please create another message for your
problem
> on this NG.
> >>> -- DC Gringo wrote: --
> >> I've got a command button to submit a value from a dropdown
list that
> should
> > then filter a SELECT query. I'm simply appending a WHERE colx
=
> ><variableSelectedFromDropdownList>. How do I pass this value into
> the event
> > handler?
> >> -- MY EVENT HANDLER
> >> Sub RunReport_OnClick(sender As Object, e As
System.EventArgs)
> >> _sqlStmt = _sqlStmt & " AND colx =
> '<variableSelectedFromDropdownList>'"
> > BindData()
> >>> End Sub
> >> -- ON MY WEB FORM
> ><ASP:Button id="cmdRunReport" Text="Run Report" runat="server"
> > onclick="RunReport_OnClick" /><ASP:dropdownlist id="Provinces"
> runat="server" Font-Size="8pt"
> > Width="100px"></ASP:dropdownlist>>>> -- MY DATA ACCESS
CODE
> >> Sub BindData()
> > Dim conString As String =
> "server=server;database=db;uid=un;pwd=pwd;"
> > Dim myDataSet1 As New DataSet
> > Dim myDataAdapter1 As New SqlDataAdapter(_sqlStmt,
conString)
> > myDataAdapter1.Fill(myDataSet1, "Communities")
> > DataGrid2.DataSource = myDataSet1.Tables("Communities")
> >> Dim myDataSet2 As New DataSet
> > Dim myDataAdapter2 As New SqlDataAdapter(_sqlStmt2,
> conString)
> > myDataAdapter2.Fill(myDataSet2, "ProvincesT")
> > Provinces.Datasource = myDataSet2.Tables("ProvincesT")
> > Provinces.DataMember = "ProvincesT"
> > Provinces.DataTextField = "clnName"
> > Provinces.DataValueField = "clnGUID"
> >>> DataGrid2.DataBind()
> > Provinces.DataBind()
> >> End Sub
> >>> _____
> > DC G
> >>
Everything looks ok. The query maybe returning the wrong data

Put a break point on the following line
Dim myDataAdapter1 As New SqlDataAdapter(_sqlStmt, conString

After the report button click event retrieve what's in the _sqlStmt string variable. You should be able to get that text from Immediate Window. Copy it over to SQL query analyzer, execute it and see what you get

Suresh

-- DC Gringo wrote: --

Suresh, here's the whole thing

<%@. Import Namespace="System.Data" %><%@. Import Namespace="System.Data.SqlClient" %><%@. Import Namespace="System.Web.UI.WebControls" %><%@. Import Namespace="System.Web.UI.WebControls.DropDownList" %><%@. Page Language="VB" Debug="true" %><script runat="server" language="VB"

Protected _sqlStmt As String =
"SELECT c1.clnName as Community, s1.clnGUID, s1.clnPriorityCorrectedTC a
Impact, PopulationKeyInfo = ISNULL(s1.clnPopulationKeyInfo,0)
MinedAreaVictimCount = ISNULL(mavc1.MinedAreaVictimCount,0), nonRecentVicti
= ISNULL(s1.clnVictimOldKilled + s1.clnVictimOldInjured, 0), SHACount
ISNULL(mavc1.SHACount,0), clnEconomicBaseTC
ISNULL(s1.clnEconomicBaseTC,'None specified'), MinDistance
ISNULL(sha1.MinDistance, 0), VictimAssist = ISNULL(mavc1.VictimAssist
'No'), clnMADoneTC = ISNULL(s1.clnMADoneTC,'Unknown') FROM tblSurvey1 s
INNER JOIN tblCity c1 ON s1.clnNearestCityGUID = c1.clnGUID INNER JOI
vwMinDistancesToNearestSHA sha1 ON s1.clnGUID = sha1.clnSurveyGUID LEF
OUTER JOIN vwMinedAreaVictimCount mavc1 ON s1.clnGUID = mavc1.clnGUID WHER
s1.clnPriorityCorrectedTC <> 'None'

Protected _sqlStmt5 As String =
"SELECT c1.clnName, s1.clnGUID FROM tblSurvey1 s1 INNER JOIN tblCity c1 O
s1.clnNearestCityGUID = c1.clnGUID ORDER BY c1.clnName

'Protected WithEvents ddlCommunities A
System.Web.UI.WebControls.DropDownLis

Sub Page_Load(Source As Object, E As EventArgs
'If Not Page.IsPostBack The
BindData(
'End I
End Su

Sub BindData(
Dim conString As String = "server=server;database=db;uid=user;pwd=pwd;
Dim myDataSet1 As New DataSe
Dim myDataAdapter1 As New SqlDataAdapter(_sqlStmt, conString
myDataAdapter1.Fill(myDataSet1, "CommunitiesT1"
DataGrid2.DataSource = myDataSet1.Tables("CommunitiesT1"

Dim myDataSet5 As New DataSe
Dim myDataAdapter5 As New SqlDataAdapter(_sqlStmt5, conString
myDataAdapter5.Fill(myDataSet5, "CommunitiesT2"
ddlCommunities.DataSource = myDataSet5.Tables("CommunitiesT2"
ddlCommunities.DataMember = "CommunitiesT2
ddlCommunities.DataTextField = "clnName
ddlCommunities.DataValueField = "clnGUID

DataGrid2.DataBind(
ddlCommunities.DataBind(

End Su

Sub SortCommand_OnClick(Source As Object, E A
DataGridSortCommandEventArgs
_sqlStmt = _sqlStmt & " ORDER BY " & E.SortExpressio
BindData(
End Su

Sub PageIndexChanged_OnClick(Source As Object, E A
DataGridPageChangedEventArgs
DataGrid2.CurrentPageIndex = E.NewPageInde
BindData(
End Su

Sub RunReport_OnClick(sender As Object, e As System.EventArgs

_sqlStmt = _sqlStmt & " AND s1.clnGUID
'"+ddlCommunities.SelectedItem.Value+"'

BindData(

End Su

</script><html><head><title></title><style
.DataGrid {font:x-small Verdana, Arial, sans-serif
</style><LINK rel="stylesheet" href="http://links.10026.com/?link=../Styles.css" type="text/css"></head><body><asp:dropdownlist Font-Size="8" id="ddlCommunities" runat="server
Width="100"></asp:dropdownlist></td><ASP:Button id="cmdRunReport" Text="Run Report" runat="server
onclick="RunReport_OnClick" /><asp:DataGri
AllowCustomPaging="false
AllowPaging="true
AllowSorting="true
AlternatingItemStyle-BackColor="#EFEFEF
AutoGenerateColumns="false"
Border="0"
Cellpadding="4"
Cellspacing="0"
CssClass="DataGrid"
DataKeyField="clnGUID"
Enabled="true"
EnableViewState="true"
HeaderStyle-BackColor="Black"
HeaderStyle-Font-Bold="True"
HeaderStyle-ForeColor="White" id="DataGrid2" runat="server"
ShowFooter="false"
OnSortCommand="SortCommand_OnClick"
OnPageIndexChanged="PageIndexChanged_OnClick"
PageSize="50"
PagerStyle-Mode="NumericPages"
PagerStyle-HorizontalAlign="Right"
ShowHeader="true"
><SelectedItemStyle Font-Bold="True" ForeColor="#663399"
BackColor="#FFCC66"></SelectedItemStyle><ItemStyle Font-Size="8pt" Font-Names="Verdana" ForeColor="#330099"
BackColor="White"></ItemStyle><HeaderStyle Font-Size="8pt" Font-Names="Verdana" Font-Bold="True"
HorizontalAlign="Center" ForeColor="#FFFFCC"
BackColor="#990000"></HeaderStyle><FooterStyle ForeColor="#330099" BackColor="#FFFFCC"></FooterStyle><Columns><asp:HyperLinkColumn DataNavigateUrlField="Community"
DataNavigateUrlFormatString="clnGUID" DataTextField="Community"
Visible="true" NavigateUrl="http://{cgi.server_name}/c={clnGUID}"
SortExpression="Community"
HeaderText="Community" text="Community" runat="server"><HeaderStyle HorizontalAlign="Left"></HeaderStyle><ItemStyle HorizontalAlign="Left"></ItemStyle></asp:HyperLinkColumn><asp:BoundColumn DataField="Impact" SortExpression="Impact"
HeaderText="Impact"></asp:BoundColumn><asp:BoundColumn DataField="PopulationKeyInfo"
SortExpression="PopulationKeyInfo" HeaderText="Population<br>Key
Info"></asp:BoundColumn><asp:BoundColumn DataField="MinedAreaVictimCount"
SortExpression="MinedAreaVictimCount"
HeaderText="Recent<br>Victims"></asp:BoundColumn><asp:BoundColumn DataField="SHACount" SortExpression="SHACount"
HeaderText="No. of<br>SHA's"></asp:BoundColumn><asp:BoundColumn DataField="clnEconomicBaseTC"
SortExpression="clnEconomicBaseTC"
HeaderText="Economic<br>Base"></asp:BoundColumn><asp:BoundColumn DataField="clnMADoneTC" SortExpression="clnMADoneTC"
HeaderText="Mine Risk<br>Education"></asp:BoundColumn><asp:BoundColumn DataField="VictimAssist" SortExpression="VictimAssist"
HeaderText="Victim<br>Assist"></asp:BoundColumn><asp:BoundColumn DataField="MinDistance" SortExpression="MinDistance"
HeaderText="Min Distance<br>to SHA"></asp:BoundColumn></columns><PagerStyle HorizontalAlign="Center" ForeColor="#330099"
Position="TopAndBottom" BackColor="#FFFFCC"
Mode="NumericPages"></PagerStyle></asp:DataGrid></form></body></html>

Passing a variable to another page

How can I navigate to another page via a button, and pass a variable to this
next page...
How can I do this via that method that I see in other sites that the url
goes like this:
http://www.google.com.br/search?hl=pt-BR
[]s...Look up the concept of querystrings
Regards
John Timney
ASP.NET MVP
Microsoft Regional Director
"Ricardo" <r_luceac@.hotmail.com> wrote in message
news:%23IPFidjDFHA.2632@.TK2MSFTNGP12.phx.gbl...
> How can I navigate to another page via a button, and pass a variable to
this
> next page...
> How can I do this via that method that I see in other sites that the url
> goes like this:
> http://www.google.com.br/search?hl=pt-BR
>
> []s...
>
Here's a nice, simple way to pass values from one page to another:
(VB.NET code)
'Add data to the context object before transferring
Context.Items("myParameter") = x
Server.Transfer("WebForm2.aspx")
Then, in WebForm2.aspx:
'Grab data from the context property
Dim x as Integer = CType(Context.Items("myParameter"),Integer)
Of course there are a number of ways to pass values from one page to
another, such as using the querystring, cookies, session,
context, saving to a temporary table in the database between each page, etc.
You'll have to decide which technique is best for your application.
Here are several good articles on the subject to help you decide.
http://msdn.microsoft.com/msdnmag/i...te/default.aspx
http://www.aspalliance.com/kenc/passval.aspx
http://www.dotnetbips.com/displayarticle.aspx?id=79
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
"Ricardo" <r_luceac@.hotmail.com> wrote in message
news:%23IPFidjDFHA.2632@.TK2MSFTNGP12.phx.gbl...
> How can I navigate to another page via a button, and pass a variable to
> this
> next page...
> How can I do this via that method that I see in other sites that the url
> goes like this:
> http://www.google.com.br/search?hl=pt-BR
>
> []s...
>

Passing a variable to another page

How can I navigate to another page via a button, and pass a variable to this
next page...

How can I do this via that method that I see in other sites that the url
goes like this:

http://www.google.com.br/search?hl=pt-BR

[]s...Look up the concept of querystrings

--
Regards

John Timney
ASP.NET MVP
Microsoft Regional Director

"Ricardo" <r_luceac@.hotmail.com> wrote in message
news:%23IPFidjDFHA.2632@.TK2MSFTNGP12.phx.gbl...
> How can I navigate to another page via a button, and pass a variable to
this
> next page...
> How can I do this via that method that I see in other sites that the url
> goes like this:
> http://www.google.com.br/search?hl=pt-BR
>
> []s...
Here's a nice, simple way to pass values from one page to another:
(VB.NET code)

'Add data to the context object before transferring
Context.Items("myParameter") = x
Server.Transfer("WebForm2.aspx")

Then, in WebForm2.aspx:

'Grab data from the context property
Dim x as Integer = CType(Context.Items("myParameter"),Integer)

Of course there are a number of ways to pass values from one page to
another, such as using the querystring, cookies, session,
context, saving to a temporary table in the database between each page, etc.
You'll have to decide which technique is best for your application.
Here are several good articles on the subject to help you decide.
http://msdn.microsoft.com/msdnmag/i...te/default.aspx

http://www.aspalliance.com/kenc/passval.aspx

http://www.dotnetbips.com/displayarticle.aspx?id=79

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net

"Ricardo" <r_luceac@.hotmail.com> wrote in message
news:%23IPFidjDFHA.2632@.TK2MSFTNGP12.phx.gbl...
> How can I navigate to another page via a button, and pass a variable to
> this
> next page...
> How can I do this via that method that I see in other sites that the url
> goes like this:
> http://www.google.com.br/search?hl=pt-BR
>
> []s...

passing a very long string to another page - javascript

I have a search page with an export to excel button. The button runs some javascript that opens a new window. This button does not post back to the server.

When someone searches the page, I build the sql query string. Then I set the buttons onClick method to pass this sql to javascript, and then to the new window (using url parameters). i.g.:

function exportToExcel(sqlQuery)
{
var newWindow = window.open("ExportToExcel.aspx?sqlQuery=" + sqlQuery , "test","width=800,height=600,resizable, scrollbars,menubar=yes");

newWindow.focus();
return false;
}

btnExportToExcel.Attributes.Add("onClick", "exportToExcel(""" & Server.UrlEncode(strExportToExcelQuery) & """); return false;")

My problem is that my sql string has become too long to be passed as a URL paramenter. Does anyone have a solution as to how I can do this?I would highly discourrage you from putting a sql query in your querystring. Querystrings are passed in plain text and you ARE (I can't stress this enough) open to SQL Injection attacks.
I thought about that, but this is an internal system only so I dont think it will be a problem. If you have any better ways of passing the string, I am open to suggestions.

The problem is that I need to open a new window for the excel file. This means that I need to do this in javascript. But how else can I pass the query to the next page then?

You can see my problem :-(
With an internal system, you are a little safer (never know about some employees these days) but I would still try and avoid it.

What if instead of client side you posted back say with a link button. On the postback you register a startup script and open a new window that way. You could put the sql statement into session or store it in a db and retrieve it, then execute it. With the db example you would only be passing a key value to the new page.
You can do this:

put the strExportToExcelQuery into an hidden field and also create a hidden field in the popup page..

then when the popup page gets opened (onload js event) for the first time you could do something like:

document.formName.txtMyPopupHiddenField.value =window.opener.formName.txtMyHiddenField.value;
document.formName.submit()

in the server code check if the hidden field has a value, if so, then now do whatever u are supposed to do. Caveats?, the popup will open the first time and then re-post to perform the action -- yucks
Great idea ccalderon. Cannot believe I didnt think of it. I'll try it today and let you know.

Jagdip