Showing posts with label query. Show all posts
Showing posts with label query. Show all posts

Thursday, March 29, 2012

pass parameter in hyperlink

Hi

I am displaying the results of a query in a datalist. There are 2 fields returned with one an icon set as a hyperlink as follows:

Smile [:)]
name

When someone clicks on the icon I would like the name parameter to be passed to a new page to be used in a new query. Can someone please point me in the right direction.

Matt

The simplest way of doing this is to append the name as a query string variable, e.g.

<a href="http://links.10026.com/?link=http://someurl.com?name=xyz">...</a>


Thanks for the quick response. My code looks as follows:

<ItemTemplate>

<asp:HyperLink ID="Hyperlink1" runat="server" NavigateUrl="~/Login.aspx"><asp:Image ID="Image1" runat="server" ImageUrl='<%# SetUrl(Eval("status")) %>' ImageAlign="Middle" /></asp:HyperLink><br />
<asp:Label ID="term_idLabel" runat="server" Text='<%# Eval("term_id") %>' Font-Names="Arial" Font-Size="Small" ForeColor="White"></asp:Label><br />
<br />
</ItemTemplate
Which displays my data as:

Smile [:)] Big Smile [:D]
name1 name2

If the user clicks on name1's icon I'd like to pass name1 as the parameter. How do I access this term_idLabel instance?
You'll want to change the NavigateUrl property in HyperLink1 so the term_id is evaluated and passed as a parameter. Try this:

NavigateUrl='<%# Eval("term_id", "~/Login.aspx?name={0}") %>'
The string will be formatted with the value for term_id replacing the {0}.

Pass SQL query to another page safely.

I want to pass an SQL Query from one page to another without the user being able to see it. Can anyone tell me how I can do this?What about putting the query in a session or encrypt it and put it in a hidden text field?
I have done this by treating the SQL (or the parameter parts of it) as a string, writing it to a database, then retrieving it from another page. Its not very elegant I know, but it works just fine if you have a specific unique key to identify your user.

regards

Mike
Two ways I can think of...If you are using response.redirect to move to the next page use session. Otherwise put the query into a page property, server.transfer to the new page, cast the httpcontext as the sending page and access the property. Or try this article on 4guys:

http://aspnet.4guysfromrolla.com/articles/020205-1.aspx
Yeah, I found somthing about the server.urlencode and server.urldecode that the article mentions. I'm not sure whether it will catch everything, but I'll see what happens.

Monday, March 26, 2012

Pass Username and Pwd to database query in WebMartix?

I have an application that uses a login screen to pass UserName and Password to a details page. Then I use a SELECT query to generate a datagrid using UserName and Pwd as WHERE clause.

I have inserted a couple of label.texts to verify the variable make the second page.

How do I get the query to limit the return to only the records matching the UserName & Pwd combination?

Thanks,
ScottYou don't really want to pass the password around your site. And hopefully you're not allowing multiple duplicate usernames as long as the password is different.

If you're using asp.net authentication then it's somewhat safe to assume that the username is valid once they're logged in.

I.E. on your login page you set an authorization cookie.

On your details page you access their username via this cookie and use that as a parameter to your stored procedure/SQL Query.

Pass Values to another page.

I am trying to a create a page that will query a SQLDB get customer
information and then pass this information on to another page creating
almost like a mail merge letter. I can get the information no problem using
a repeater but how do I pass <%#container.DataItem("Value1")%> to another
page.

Thx.Hi

Put information you want to share between pages either in
Session Object or Cache Object.

Ravikanth

>--Original Message--
>I am trying to a create a page that will query a SQLDB
get customer
>information and then pass this information on to another
page creating
>almost like a mail merge letter. I can get the
information no problem using
>a repeater but how do I pass <%#container.DataItem
("Value1")%> to another
>page.
>Thx.
>
>.
Can u give me an example of this?

"Ravikanth[MVP]" <dvravikanth@.hotmail.com> wrote in message
news:015f01c351fa$14740ed0$a101280a@.phx.gbl...
> Hi
> Put information you want to share between pages either in
> Session Object or Cache Object.
> Ravikanth
>
> >--Original Message--
> >I am trying to a create a page that will query a SQLDB
> get customer
> >information and then pass this information on to another
> page creating
> >almost like a mail merge letter. I can get the
> information no problem using
> >a repeater but how do I pass <%#container.DataItem
> ("Value1")%> to another
> >page.
> >Thx.
> >.

Saturday, March 24, 2012

Pass variable through include url

Well,
I have made a template which shows the header.
Now in an empty page I include it on the top and this way it shows when I query the page also the header.
This works.
Now I want in the header there is a cell which is empty to show a message.
This message is dynamic, so it depends on what you give as message.
I could it make that when I query index.aspx?message=test that in my header(header.aspx) it shows the message test.
Now want to do it this way.
I query index.aspx
but in index.aspx I do an include this way:
<!--#include file="template/header.aspx"-->
that I make it this way:
<!--#include file="template/header.aspx?message:test"-->
this way I can show on my header a message in that empty cell without the user seeing it in the url.
Is this possible?

Eeek...
You're really going about this a hard way.
If you aren't using 2.0 (which I'm assuming you aren't) then I'd create the header as a UserControl.
Then just plop it on the page. You can easily create a Public Property on the header then, that is accessible from the page, that you can set the Text to...

Passing 2 variables through query string

Hi,

I know normally how to pass a value through a query string but this is complicated by wanting to pass two values. The first value is passed from a datagrid hyper link column i.e

<asp:HyperLinkColumn DataNavigateUrlField="PK_StockOrderID" DataNavigateUrlFormatString="AssignedDetail.aspx?id={0}"
DataTextField="PK_StockOrderID" HeaderText="Order ID"></asp:HyperLinkColumn>


This allows the user to view order details in the next page by passing the order id through the query string to the next page. However I also have a dropdown list box on the same page as the datagrid and would like to pass another parameter in the same query string based on the value selected in the list box.

Any ideas how I can do this?

If this doesnt make sense pls say and I will explain further.

Will something like this work if I have a function in my codebehind which returns the value of the dropdown list?
<asp:HyperLinkColumn DataNavigateUrlField="PK_StockOrderID" DataNavigateUrlFormatString="AssignedDetail.aspx?id={0} ?site=<%# ReturnSite %>"
DataTextField="PK_StockOrderID" HeaderText="Order ID"></asp:HyperLinkColumn>Normaly additional parameters in a querystring are separated by an ampersand (&)... not the ? (that's only on the first one to mark the begining of the QS.) and no spaces.

-tg
it's not calling the function at the moment I think this is the problem syntax

<asp:HyperLinkColumn DataNavigateUrlField="PK_StockOrderID" DataNavigateUrlFormatString="AssignedDetail.aspx?id={0}&site='<%# ReturnSite %>'"
Change of plan. Can I use the selected index changed property to set the DataNavigateUrlFormatString. That would be better but I cannot find the correct syntax?
Honestly, it's out of my realm of expertise... I've not had the chance to delve into ASP.NET, so I don't know for sure what the proper syntax is... I don't even know enough to point you in the right direction other than MSDN... Sorry...

-tg
Passed variable to a public class instead.
The ItemCommand event of the datagrid could have done this for you. Basically, you could retrieve the value from the Item that sent the Command (convert to DDL, get selected value) and then gotten the value from the standalone DDL in your page, concatenated them and then performed a Response.Redirect.

Wednesday, March 21, 2012

Passing a CSV file into APSX page and returning query from SQL server using CSV data?

Is this possible basically?

I have a CSV file that contains a list of barcodes, I would like to create a page that will upload this into a temp table of some kind and query a SQL using the CSV file to join the data to the table.

This would then output the result to a list on the page.


Any ideas? As yet I haven't managed to start anything on ASP.net yet!

Of course it's possible. Almost anything is possible. When you get to your coding you should ask the specific questions that you need answered.


Here is one way on how to do this

1. Read your file using FileStream.
2. Create a datatable and its columns.
3. Loop through your file (using FileStream) and populate your datatable.
4. Create a dataview and set to the datatable.
5. Use rowfilter to filter out data you don't want to show.
6. Bind the data to your DataGrid or DataList to display the data onto the page.


Many thanks for your reply, more the kinda reply that I was hoping for.

The method that you have said, trying to understand this:

Does part 3 put the data into the database?

Where do I execute a query/sp to get the correct additional data back? (As more relevant data will be coming back based on a join to the new fields in the table)?

Thanks

Passing a query string

I used Repeater control to bind data and I need something like

<a href="http://links.10026.com/?link=showsection.aspx?section=<%# DataBinder.Eval(Container.DataItem, "SectionId") %>"><%# DataBinder.Eval(Container.DataItem, "Name") %></a>

How can I pass what sectionId is selected on the showsection.aspx page? And oh, is this a good way of having something like a navigator? Or is there any other better way? Thanks.Didn't understand the second part of your question...
I solved it through
public void DisplaySections()
{
SectionCollection sectionCollection = SectionAccess.ListExcludeInactive();
Response.Write("<table width='100%' cellspacing='0'>");
foreach (Section section in sectionCollection)
{
Response.Write(string.Format(@."<tr><td class='navbar'><a href='showsection.aspx?section={0}'>{1}</a></td></tr>", section.SectionId, section.Name));
}
Response.Write("<tr><td class='navbar'> </td></tr></table>");
}

and get the section with
public void DisplayLatestWithSection()
{
int id = int.Parse(Request.QueryString["section"].ToString());
Article article = ArticleAccess.LatestWithSection(id);
if (article != null)
{
Response.Write(string.Format(@."<span class='teaser-head'><a href='showarticle.aspx?article={0}'>{1}</a></span><br>", article.ArticleId, article.HtmlTeaserHead));
Response.Write(article.HtmlTeaserDate + "<br>");
Response.Write(article.HtmlTeaserText);
}
}

at the showsection.aspx. Or is there any better way of getting the query string name and value?

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 an '&' as part of the parameter's value in a query string

I have a situation where I will collect text from a textbox and pass that
text as one of the parameters in another pages query string. the problem is
that if the user types in a '&' as part of the text message, the page being
called thinks the '&' is parsing out another parameter. Using JavaScript,
what should I do to pass the entire message in the query string?

Thanks.

--
moondaddy@dotnet.itags.org.newsgroup.nospammoondaddy wrote:

Quote:

Originally Posted by

I have a situation where I will collect text from a textbox and pass that
text as one of the parameters in another pages query string. the problem is
that if the user types in a '&' as part of the text message, the page being
called thinks the '&' is parsing out another parameter. Using JavaScript,
what should I do to pass the entire message in the query string?
>
Thanks.


Use the encodeURIComponent function to encode the value that you put in
the URL.

You should do this for any values that you put in an URL that might
contain characters that needs encoding.

--
Gran Andersson
_____
http://www.guffa.com
On Sep 12, 9:19 am, "moondaddy" <moonda...@.newsgroup.nospamwrote:

Quote:

Originally Posted by

I have a situation where I will collect text from a textbox and pass that
text as one of the parameters in another pages query string. the problem is
that if the user types in a '&' as part of the text message, the page being
called thinks the '&' is parsing out another parameter. Using JavaScript,
what should I do to pass the entire message in the query string?
>


& = %26
Alexey Smirnov wrote:

Quote:

Originally Posted by

On Sep 12, 9:19 am, "moondaddy" <moonda...@.newsgroup.nospamwrote:

Quote:

Originally Posted by

>I have a situation where I will collect text from a textbox and pass that
>text as one of the parameters in another pages query string. the problem is
>that if the user types in a '&' as part of the text message, the page being
>called thinks the '&' is parsing out another parameter. Using JavaScript,
>what should I do to pass the entire message in the query string?
>>


>
& = %26
>


That is correct, but that only solves the problem with that specific
character. There are several other characters that are not valid in a
value in a query string, like spaces for example.

--
Gran Andersson
_____
http://www.guffa.com
Thanks!

encodeURIComponent worked perfect.

"Gran Andersson" <guffa@.guffa.comwrote in message
news:uFyGU9Q9HHA.980@.TK2MSFTNGP06.phx.gbl...

Quote:

Originally Posted by

moondaddy wrote:

Quote:

Originally Posted by

>I have a situation where I will collect text from a textbox and pass that
>text as one of the parameters in another pages query string. the problem
>is that if the user types in a '&' as part of the text message, the page
>being called thinks the '&' is parsing out another parameter. Using
>JavaScript, what should I do to pass the entire message in the query
>string?
>>
>Thanks.


>
Use the encodeURIComponent function to encode the value that you put in
the URL.
>
You should do this for any values that you put in an URL that might
contain characters that needs encoding.
>
--
Gran Andersson
_____
http://www.guffa.com