Thursday, March 29, 2012
pass my dropdownlist
i'm in vs2005 designer view editing a formview's edit template. i have a
dropdownlist and i'm trying to bind the SelectedValue to a custom expression
.
i was wondering if it is possible to pass the dropdownlist object down to th
e
code-behind? i tried using the this keyword but that didn't work.
thanks,
rodcharCan you please eloborate a little more?
Are you trying to access the Dropdownlist in the designer or in some
routine in the code behind?
If it is in the code behind of the samepage where the dropdown is declared,
I do not see any problem accessing it.
Can you give an example of your code?
--
>Thread-Topic: pass my dropdownlist
>thread-index: Acg2ih2bZVRS0qv3TbWr/MzGXJ0Yjg==
>X-WBNR-Posting-Host: 24.214.205.110
>From: examnotes <rodchar@.discussions.microsoft.com>
>Subject: pass my dropdownlist
>Date: Tue, 4 Dec 2007 07:27:01 -0800
>Lines: 8
>Message-ID: <31752D5F-72C8-4B2C-ACA5-E868CEF35F42@.microsoft.com>
>MIME-Version: 1.0
>Content-Type: text/plain;
> charset="Utf-8"
>Content-Transfer-Encoding: 7bit
>X-Newsreader: Microsoft CDO for Windows 2000
>Content-Class: urn:content-classes:message
>Importance: normal
>Priority: normal
>X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.2992
>Newsgroups: microsoft.public.dotnet.framework.aspnet
>Path: TK2MSFTNGHUB02.phx.gbl
>Xref: TK2MSFTNGHUB02.phx.gbl microsoft.public.dotnet.framework.aspnet:52357
>NNTP-Posting-Host: tk2msftibfm01.phx.gbl 10.40.244.149
>X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
>hey all,
>i'm in vs2005 designer view editing a formview's edit template. i have a
>dropdownlist and i'm trying to bind the SelectedValue to a custom
expression.
>i was wondering if it is possible to pass the dropdownlist object down to
the
>code-behind? i tried using the this keyword but that didn't work.
>thanks,
>rodchar
>
Thank You,
Nanda Lella,
This Posting is provided "AS IS" with no warranties, and confers no rights.
you're right, i just realized how obvious my question was after i posted. i
apologize.
"Nanda Lella[MSFT]" wrote:
> Can you please eloborate a little more?
> Are you trying to access the Dropdownlist in the designer or in some
> routine in the code behind?
> If it is in the code behind of the samepage where the dropdown is declared
,
> I do not see any problem accessing it.
> Can you give an example of your code?
> --
> expression.
> the
> --
> Thank You,
> Nanda Lella,
> This Posting is provided "AS IS" with no warranties, and confers no rights
.
>
pass my dropdownlist
i'm in vs2005 designer view editing a formview's edit template. i have a
dropdownlist and i'm trying to bind the SelectedValue to a custom expression.
i was wondering if it is possible to pass the dropdownlist object down to the
code-behind? i tried using the this keyword but that didn't work.
thanks,
rodcharCan you please eloborate a little more?
Are you trying to access the Dropdownlist in the designer or in some
routine in the code behind?
If it is in the code behind of the samepage where the dropdown is declared,
I do not see any problem accessing it.
Can you give an example of your code?
-------
Quote:
Originally Posted by
>Thread-Topic: pass my dropdownlist
>thread-index: Acg2ih2bZVRS0qv3TbWr/MzGXJ0Yjg==
>X-WBNR-Posting-Host: 24.214.205.110
>From: =?Utf-8?B?cm9kY2hhcg==?= <rodchar@.discussions.microsoft.com>
>Subject: pass my dropdownlist
>Date: Tue, 4 Dec 2007 07:27:01 -0800
>Lines: 8
>Message-ID: <31752D5F-72C8-4B2C-ACA5-E868CEF35F42@.microsoft.com>
>MIME-Version: 1.0
>Content-Type: text/plain;
>charset="Utf-8"
>Content-Transfer-Encoding: 7bit
>X-Newsreader: Microsoft CDO for Windows 2000
>Content-Class: urn:content-classes:message
>Importance: normal
>Priority: normal
>X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.2992
>Newsgroups: microsoft.public.dotnet.framework.aspnet
>Path: TK2MSFTNGHUB02.phx.gbl
>Xref: TK2MSFTNGHUB02.phx.gbl microsoft.public.dotnet.framework.aspnet:52357
>NNTP-Posting-Host: tk2msftibfm01.phx.gbl 10.40.244.149
>X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
>
>hey all,
>i'm in vs2005 designer view editing a formview's edit template. i have a
>dropdownlist and i'm trying to bind the SelectedValue to a custom
expression.
Quote:
Originally Posted by
>i was wondering if it is possible to pass the dropdownlist object down to
the
Quote:
Originally Posted by
>code-behind? i tried using the this keyword but that didn't work.
>
>thanks,
>rodchar
>
--
Thank You,
Nanda Lella,
This Posting is provided "AS IS" with no warranties, and confers no rights.
you're right, i just realized how obvious my question was after i posted. i
apologize.
"Nanda Lella[MSFT]" wrote:
Quote:
Originally Posted by
Can you please eloborate a little more?
Are you trying to access the Dropdownlist in the designer or in some
routine in the code behind?
If it is in the code behind of the samepage where the dropdown is declared,
I do not see any problem accessing it.
>
Can you give an example of your code?
>
-------
Quote:
Originally Posted by
Thread-Topic: pass my dropdownlist
thread-index: Acg2ih2bZVRS0qv3TbWr/MzGXJ0Yjg==
X-WBNR-Posting-Host: 24.214.205.110
From: =?Utf-8?B?cm9kY2hhcg==?= <rodchar@.discussions.microsoft.com>
Subject: pass my dropdownlist
Date: Tue, 4 Dec 2007 07:27:01 -0800
Lines: 8
Message-ID: <31752D5F-72C8-4B2C-ACA5-E868CEF35F42@.microsoft.com>
MIME-Version: 1.0
Content-Type: text/plain;
charset="Utf-8"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
Content-Class: urn:content-classes:message
Importance: normal
Priority: normal
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.2992
Newsgroups: microsoft.public.dotnet.framework.aspnet
Path: TK2MSFTNGHUB02.phx.gbl
Xref: TK2MSFTNGHUB02.phx.gbl microsoft.public.dotnet.framework.aspnet:52357
NNTP-Posting-Host: tk2msftibfm01.phx.gbl 10.40.244.149
X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
hey all,
i'm in vs2005 designer view editing a formview's edit template. i have a
dropdownlist and i'm trying to bind the SelectedValue to a custom
expression.
Quote:
Originally Posted by
i was wondering if it is possible to pass the dropdownlist object down to
the
Quote:
Originally Posted by
code-behind? i tried using the this keyword but that didn't work.
thanks,
rodchar
>
--
>
Thank You,
Nanda Lella,
>
This Posting is provided "AS IS" with no warranties, and confers no rights.
>
>
Monday, March 26, 2012
pass through value of DropDownList ListItem into a string
I'm building an email form that uses a DropDownList to select the e-mail address via alias. Here is a portion of the control:
<asp:DropDownList id="ddlRecipient" CssClass="text-blue" AutoPostBack="true" runat="server">
<asp:ListItem Value="none" Selected="true">Please select from this list.</asp:ListItem>
<asp:ListItem Value="mornings">the morning show</asp:ListItem>
<asp:ListItem Value="news">News - newscasts, stories, comments</asp:ListItem>
</asp:DropDownList
Here is the code I am supposedly using to pass through the value:
Sub SendMe ()
Dim ddlRecipient As String
Dim ddlRecipientEmail As String = ddlRecipient & "@dotnet.itags.org.mydomain.com"
Response.Write(ddlRecipientEmail & " -- this is the email address you just sent")
End Sub
(The Response.Write line will be replaced by my email generation code, and I will use ddlRecipientEmail as the "from" field.)
However, all I get from the Response.Write is:
@dotnet.itags.org.mydomain.com -- this is the email address you just sent
So it's not passing through the value. How do I get it to do that?
Also, I'm going to do an If/Then/Else statement that, if "none" is the value, you get a popup and the program stops running. Anyone got a quick way to do that?
Appreciate the help.
ddlRecipient.SELECTEDVALUE
I actually just found that and it is working now.Thank you.
Curt_C:
ddlRecipient.SELECTEDVALUE
Pass value in "Inherits System.Web.UI.WebControls.DropDownList"?
This is the code I have at this moment:
Public Class ColoredDropDownList
Inherits System.Web.UI.WebControls.DropDownListProtected Overrides Sub RenderContents(ByVal writer As System.Web.UI.HtmlTextWriter)
Dim ...etc..
MyConnection = New SqlConnection(connectionstring)
MyCommand = New SqlDataAdapter("SELECT bgcolor FROM buffer WHERE page='" + Session("fileName").ToString() + "'", MyConnection)
I hope someone can help me. Thanks!You can access them inside a control via Context property which returns reference to the current HttpContext. To access Request or Session that would be Context.Request or Context.Session and so on.
Pass value to second DropDownList from the first one
I want pass value to 2nd DropDownList from 1st one. I use "DropDownList1.SelectedValue", but got error message." can't transfer data type from varchar,..." Yes, in Database, it is varchar type.
Here is a source code:
private void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e)
{
string sql = "select Address from myTable where Name=" + DropDownList1.SelectedValue ;
SqlConnection con = new SqlConnection(connectionString);
SqlDataAdapter da = new SqlDataAdapter(sql, con);
DataSet ds = new DataSet();
da.Fill(ds, "myTable");
DataView dv=ds.Tables [0].DefaultView ;
DropDownList2.DataTextField="Address";
DropDownList2.DataValueField ="Address";
//DropDownList2.DataSource =ds.Tables[0].DefaultView;
DropDownList2.DataSource=dv;
DropDownList2.DataBind ();
con.Close();
}
Two things.
1) I would use a SqlDataReader to populate the DropDownList. It is 100x faster than a DataSet.
2) Try DropDownList1.SelectedItem.Value to get the value of the DropDownList
move your datasource code line above both your datatextfield and datavaluefield
[edit]
He is right about the speed--much faster.
I did try: DropDownList1.SelectedItem.Value, but got same error msg.
You are missing the single quotes around the parameter, try:
string sql = "select Address from myTable where Name='" + DropDownList1.SelectedValue + "'" ;
Better NOW.
Wednesday, March 21, 2012
passing a DropdownList value to another wizard step?
NewsArticle from the combobox to edit. The second wizardStep (pressing next)
loads the whole database record into a form. The third step would be for
them to confirm the changes before submitting. I know how to get the confirm
part to work as well as the update part itself but how would I get the
combobox step to load the whole record into a form in the next wizardStep?On 10 Jan, 00:11, "Andy B" <a_bo...@.sbcglobal.net> wrote:
> I have a wizard that has 3 wizardSteps. The first one is selecting a
> NewsArticle from the combobox to edit. The second wizardStep (pressing nex
t)
> loads the whole database record into a form. The third step would be for
> them to confirm the changes before submitting. I know how to get the confi
rm
> part to work as well as the update part itself but how would I get the
> combobox step to load the whole record into a form in the next wizardStep?
Hi Andy,
Could you not put the combo box value into the query string, or into
session?
Another, more complex apprach would be to write the value using
JavaScript into a hidden field value then pick it up as step 2 loads.
HTH,
Jon
www.nantwichonline.com/pubs
Passing a parameter to get results to post to a datagrid
here is my code:
<%@dotnet.itags.org. Page Language="VB" ContentType="text/html" ResponseEncoding="iso-8859-1" %>
<%@dotnet.itags.org. Register TagPrefix="MM" Namespace="DreamweaverCtrls" Assembly="DreamweaverCtrls,version=1.0.0.0,publicKeyToken=836f606ede05d46a,culture=neutral" %>
<MM:DataSet
id="DataSetResults"
runat="Server"
IsStoredProcedure="false"
ConnectionString='<%# System.Configuration.ConfigurationSettings.AppSettings("MM_CONNECTION_STRING_CPAR") %>'
DatabaseType='<%# System.Configuration.ConfigurationSettings.AppSettings("MM_CONNECTION_DATABASETYPE_CPAR") %>'
CommandText='<%# "SELECT * FROM dbo.ListofNonconformities WHERE ""Reference Document"" = ?" %>'
Debug="true" PageSize="10"
><Parameters>
<Parameter Name="@dotnet.itags.org.Reference Document" Value='<%# IIf((Request.Form("FRefDoc") <> Nothing), Request.Form("FRefDoc"), "") %>' Type="WChar" /></Parameters></MM:DataSet>
<MM:PageBind runat="server" PostBackBind="true" />
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<form action="" method="post" name="FRefDoc" id="FRefDoc" runat="server">
<p>
<% DDRefDoc.SelectedIndex = DDRefDoc.Items.IndexOf(DDRefDoc.Items.FindByValue(DataSetResults.FieldValue("Reference Document", Nothing) )) %><asp:DropDownList ID="DDRefDoc" runat="server" DataSource="<%# DataSetResults.DefaultView %>" DataTextField="Reference Document" DataValueField="Reference Document"></asp:DropDownList>
<asp:Button ID="BSubmit" runat="server" Text="Submit" /></p>
<p>
<asp:DataGrid id="DataGridResults"
runat="server"
AllowSorting="False"
AutoGenerateColumns="false"
CellPadding="3"
CellSpacing="0"
ShowFooter="false"
ShowHeader="true"
DataSource="<%# DataSetResults.DefaultView %>"
PagerStyle-Mode="NextPrev"
AllowPaging="true"
AllowCustomPaging="true"
PageSize="<%# DataSetResults.PageSize %>"
VirtualItemCount="<%# DataSetResults.RecordCount %>"
OnPageIndexChanged="DataSetResults.OnDataGridPageIndexChanged"
>
<HeaderStyle HorizontalAlign="center" BackColor="#E8EBFD" ForeColor="#3D3DB6" Font-Name="Verdana, Arial, Helvetica, sans-serif" Font-Bold="true" Font-Size="smaller" />
<ItemStyle BackColor="#F2F2F2" Font-Name="Verdana, Arial, Helvetica, sans-serif" Font-Size="smaller" />
<AlternatingItemStyle BackColor="#E5E5E5" Font-Name="Verdana, Arial, Helvetica, sans-serif" Font-Size="smaller" />
<FooterStyle HorizontalAlign="center" BackColor="#E8EBFD" ForeColor="#3D3DB6" Font-Name="Verdana, Arial, Helvetica, sans-serif" Font-Bold="true" Font-Size="smaller" />
<PagerStyle BackColor="white" Font-Name="Verdana, Arial, Helvetica, sans-serif" Font-Size="smaller" />
<Columns>
<asp:BoundColumn DataField="ISO 9001 Clause"
HeaderText="ISO 9001 Clause"
ReadOnly="true"
Visible="True"/>
<asp:BoundColumn DataField="Expr1"
HeaderText="Expr1"
ReadOnly="true"
Visible="True"/>
<asp:BoundColumn DataField="Action To:"
HeaderText="Action To:"
ReadOnly="true"
Visible="True"/>
<asp:BoundColumn DataField="Description of Nonconformity"
HeaderText="Description of Nonconformity"
ReadOnly="true"
Visible="True"/>
<asp:BoundColumn DataField="Verified By"
HeaderText="Verified By"
ReadOnly="true"
Visible="True"/>
<asp:BoundColumn DataField="Submission Date"
HeaderText="Submission Date"
ReadOnly="true"
Visible="True"/>
<asp:BoundColumn DataField="Completion Date"
HeaderText="Completion Date"
ReadOnly="true"
Visible="True"/>
<asp:BoundColumn DataField="Verification Date"
HeaderText="Verification Date"
ReadOnly="true"
Visible="True"/>
<asp:BoundColumn DataField="Reference Document"
HeaderText="Reference Document"
ReadOnly="true"
Visible="True"/>
<asp:BoundColumn DataField="Process Owner"
HeaderText="Process Owner"
ReadOnly="true"
Visible="True"/>
<asp:BoundColumn DataField="Remarks"
HeaderText="Remarks"
ReadOnly="true"
Visible="True"/>
</Columns>
</asp:DataGrid>
</p>
<p> </p>
</form>
</body>
</html>that is very good
thank you
Friday, March 16, 2012
passing a value to an event handler from dropdownlist
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>