Forms Data Controls :: Use DropDownList To Query Db To Include All Values With Exceptions
Jan 21, 2011
Trying to use a dropdownlist to query a database so that it will return all values except 1 (or more in future versions).
For example, assume you had a simple table name "MYFRIENDS" which has two fields named "GROUP" and "NAME" with the following records:
Group
Name
A
John
B
Jane
C
Tony
D
Sue
What I want to do is create a DropDownList that has only 2 list items related to the "GROUP" field. The first list item should return records from the database related to Group A only. Then, the second list item should return all other records EXCLUDING those belonging to Group A.
The drop down list should look something like this (I've put a question mark where I don't know what to do):
[Code]....
After the selection is chosen in the above drop down list, it should query the database and return the desired result. I'm using an AccessDataSource with select parameters. Here's a sample of what that looks like:
[Code]....
Things I've tried that didn't work:
I tried using "Not A" as the the 2nd list item's value. I was thinking p1 would be replaced with the value "Not A" and the query would read "WHERE GROUP LIKE Not A". But, the query syntax "Like Not" is technically wrong. I tried changing the Where Clause to "WHERE GROUP p1" and then replaced the list item's value to "LIKE A" and the second to "NOT LIKE A". Again, I was thinking p1 would be replaced to read "WHERE GROUP LIKE A" and "WHERE GROUP NOT LIKE A". I also tried changing the "SelectCommand" itself so that after the dropdownlist changed, it would first change the selectcommand first and then run the query.
Why the first 2 items didn't work became somewhat obvious to me after thinking about it for a little while. However, I would think the 3rd one would/should work... as long as you have the sequence of events correct which up to this point I haven't been able to figure out.
View 3 Replies
Similar Messages:
Jul 13, 2010
I have a listview that I am trying to initiate the connection string in codebehind. When I do it, I get the following error:The ConnectionString property has not been intialized.I know that I am successfully creating the connection string in codebehind because all other controls populate correctly from the dsame database.I do not get an error if I initiate the connection string in the html code.
View 6 Replies
Jan 18, 2010
I have a dropdownlist used to select a directory for a gridview to show images in the directory.
I am wondering how I can include the value of the dropdownlist in the formatstring or some way to have it change.
I tried
<% "~" & cboFilePath.SelectedValue & "{0}"%>
with no luck. my dropdown containes "/images/" and "/images/uploadedPhotos/" and the gridview lists the files, but the images dont show.
View 2 Replies
Feb 17, 2011
I am using VS 2005.I want to include Chart reading values from an XML file.
View 3 Replies
Jan 6, 2010
I have a parent repeater that lists the sections of the website. this repeater binds to display a table that contain another repeater of the website pages .. or may display a table that contains another two repeaters of the projects categories and sub-categories.Until now everything is going fine.
The problem comes when I try to include a query of the section ID to the link of the project categories (DataView of the projects repeaters does not contain SectionID)my question is : is there any way to call the SectionID of the first repeater in my projects categories and sub-categories repeaters?Here is my code:
[Code]....
the code behind is as follow:
[Code]....
View 8 Replies
Feb 17, 2010
I have dropdownlist of dates and depending on the date that the user selects from list, I would like to filter records that fall between the startyear and finishyear columns in the datasource. (My the problem is that I do not know how to declare the Startyear and Endyear from the query in the code as they appear underlined - probably the BETWEEN syntax is wrong too).
yYear = DropDownList1.Text
Using connection As New SqlConnection("Data Source=CHRIS-PCSQLEXPRESS;Initial Catalog=TorGHL;Integrated Security=True")
Dim cmd As String
cmd = "SELECT BarDetails.*, MenuHeadingId AS Expr1 FROM BarDetails WHERE (MenuHeadingId = 2)" & "WHERE " & yYear & " BETWEEN " & "(" &
StartYear & ")" & " AND " & "(" & EndYear & ")"
connection.Open()
Dim dapubcb As New SqlDataAdapterDim sqlcomm
As
New SqlCommand(cmd, connection)
dapubcb.SelectCommand = sqlcomm
Dim dspubcb As New DataSet("BarDetails")
dapubcb.Fill(dspubcb, "BarDetails")
View 4 Replies
Oct 9, 2012
UsingĀ dropdown in gridview and bind the values in dropdown then based on dropdown display the value in another column.
View 1 Replies
Mar 16, 2011
How to get a dropdown list to use my own query, because i couldnt figure out how to use my variables in asp.net's configuration.
how i can get the dropdown list to read the data returned from my query?
protected void
Page_Load(object sender,
EventArgs e)
{
[Code]....
View 5 Replies
Jun 22, 2010
I have an application that I am developing using ASP.Net with visual basic code. I have a table called "Customers" that contains 3 fields. The name of each field is "Name", "LocationA", and "LocationB". I want to code a select query that list two columns. The first column should contain the field "Name". I want the second column to contain the value in the field "LocationB" if "LocationB" is not null, else I want the second column to contain the value in the field "LocationA".
View 4 Replies
Mar 15, 2011
I have a dropdownlist and a button(btnSend).
protected void btnSend_Click(object sender, EventArgs e)
{
InsertIntoTemporary();
LoadAddressdetails();
MassSendOut();
}
What i need to do is as follows;
1) Once i select the item in the dropdownlist, it will extract data from my sql query which is :
string mySQL = "SELECT * FROM examtimetable WHERE subject_name= '" + dd_cat.SelectedValue + "'";
Once seleted,it will display everything in a gridview1.
subject_id subject_name admission_no date venue seat_no
View 2 Replies
Apr 21, 2010
I have a Gridview which I'm populating through code behind. A couple of columns of the gridview I've set up to be drop down lists. What I want, is that when I run my Insert query, it takes the drop down list selected value, finds the appropriate ID and uses that ID as part of the insert query.
Below is my select and insert query.
[Code]....
This is the related asp:
[Code]....
View 22 Replies
Apr 28, 2010
How to query a SQL database with 3 field values ( From date, To date and based on a Dropdown Selection)
I use the below code:
sqls = "SELECT * FROM QlyData where Date >='" + txtstartdate.Text +
"' and Date<='" + txtenddate.Text +
"' and '" + supportgrp.Text +
"'";
Supportgrp.text is a Dropdown selection.I get the below error:
Exception Details: System.Data.SqlClient.SqlException: An expression of non-boolean type specified in a context where a condition is expected, near 'Database'.
View 2 Replies
Dec 29, 2010
I want to use multiple selected values from my list box to my sql query as how can i do this
i fill my listbox with following code to use selected multiple values in my sql delete query for deleting selected records
Dim connect, strsql As String
View 2 Replies
Oct 29, 2010
I have a dropdownlist which gets the data from the oracle database, the values that contains quotes example "Apple's" or "Website's" or not getting seelcted from the list except these values remaining values have no issues.
View 3 Replies
Jan 17, 2011
my c# web application populating dropdowns with datas at run time... i.e my web form contains 3 dropdowns and one gridview.. dropdown1 populate with 'pgmtitle' which is fetch from database,when user select one item-pgmtitle from dropdown1,participants(BadgeNo,Name)
of that pgm will be populated in gridview. when user click on the participant badgeno,dropdownlist3 will poputated with recieving officers name.. wen user select one of the recieving officer from dropdown3,his designation is dispalyed in a textbox,and dropdon2
will populated with feedback sentdate... this is my requirement... and my pblm is, when i choose another pgmtilte(say pgmtilte2) from dropdownlist1,previous value associated with(pgmtilte1) appended with dropdown2 and dropdown3.. here is my HTML code:-
[Code]....
View 9 Replies
Jan 25, 2011
i have created a dynamic dropdownlist. i need to get the selected values from the list and store it in my sql database. i am new to asp.
View 5 Replies
Jun 10, 2010
I have a DropDownList on my webpage using an Access Database to fill it. However in my database record there a multible values with the same name.
My situation now:
MyDropDownList1
-ValueBaarlo
-ValueBaarlo
-ValueVenlo
-ValueMaasbree
-ValueMaasbree
-ValueMaasbree
-ValueMaasbree
What I want:
MyDropDownList1
-ValueBaarlo
-ValueVenlo
-ValueMaasbree
I only want to show every value (name) just once!
View 4 Replies
Aug 4, 2010
I got a gridview -CompGrid, having 3 columns - Dept, Employees, Status.
The 'Status' tab need to be edited. So that I put a Dropdownlist as an Itemtemplate and connected the 'DataValueField' as 'Status'.
Now I can edit each row by row only. Some times it needs to update all the employees status in one department.
So that I placed 2 more dropdownlists in outside of gridview.
1. Department List, 2. Status List.
My requirement is this, When I select one department and corresponding status, it should update all the records of that department in the grid.
View 3 Replies
Jan 31, 2010
My database has 4 colums;
TraditionalID-------------TraditionalName------------Singles-----------Suppers
Singles and suppers are money fields for the price of same item. A bit like the price of a Small, Medium or Large item. What I would like to do is display the 'Singles' price and 'Suppers' price in seperate listitems so the user can choose 1 of them.
GridView:
Traditional Name__________Size
Chicken-------------------[DROPDOWNLIST]
DropDownList:
Price of Single is: £1.50
Price of Supper is: £2.50
My page loads up with the correct items in TraditionalName colum but the DropDownList is completely empty. I'm aware I don't have anything in for DataValueField and DataTextField but I have tried putting things in these attributes, like Suppers and Singles, but nothing works, so I have taken them out below.
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="TraditionalID" DataSourceID="SqlDataSource1">
<Columns>
<asp:BoundField DataField="TraditionalID" HeaderText="TraditionalID" InsertVisible="False" ReadOnly="True" SortExpression="TraditionalID" Visible="False" />
<asp:BoundField DataField="TraditionalName" HeaderText="Meal" SortExpression="TraditionalName" />
<asp:templateField HeaderText="Size">
<ItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource2">
</asp:DropDownList>
<asp:HiddenField ID="RowTraditionalName" runat="server" Visible="false" Value='<%# Eval("TraditionalName") %>' />
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:The CodfatherConnectionString %>"
SelectCommand="SELECT Suppers AS Suppers, Singles AS Singles FROM [Traditional] WHERE TraditionalName = @TraditionalName">
<SelectParameters>
ControlParameter Name="TraditionalName" Type="String" ControlID="RowTraditionalName" PropertyName="Value" />
</SelectParameters>
</asp:SqlDataSource>
</ItemTemplate>
</asp:templateField>
</Columns>
</asp:GridView>
View 1 Replies
Apr 19, 2010
See what happens when you answer my questions! I come back! No good deed goes unpunished. I've built an Update form where my visitor can update data in dbase. I have a formview with several dropdown lists; none of which will update the table (all the textboxes, checkboxes and even Ajax enabled calendar work just fine). In the form below, visitor selects a CareerCluster from the ddl. Upon postback, the next ddl (pathwayListBox) populates with related data using the CareerCluster.selectedvalue in a query. At the same time, tsaOrgsDropDownList is also populated based upon the first ddl (CareerCluster).
When user selects from the tsaOrgsDropDownList the final ddl (tsaDropDownList) is populated. All this various selecting/populating works just fine on the form. The problem is: Nothing is updated to the table upon clicking the Update button. All other form fields do post as their supposed to except, I have other ddls on the page that are not related to the above series and they won't post either. My thought is that somehow, this is related to the postbacking going on. That posting back is overwriting the selectedValues with null or something.
<asp:FormView ID="courseUpdateFormView" runat="server" BackColor="White" BorderColor="White" BorderStyle="Ridge" BorderWidth="2px" CellPadding="3" CellSpacing="1" DataKeyNames="CTECourseID" DataSourceID="formviewSqlDataSource" Width="715px">
<FooterStyle BackColor="#C6C3C6" ForeColor="Black" />
<RowStyle BackColor="#DEDFDE" ForeColor="Black" />
<EditItemTemplate>
<table align="center" width="700" border="1" cellpadding="10" cellspacing="2" bgcolor="White">
<%--A whole bunch of textboxes goes here--%>
<tr>
<td bgcolor="#dadada">
<strong>Number of HS Credits:</strong> <span>(Standards-based districts use the <em>Other</em> form field.)</span>
</td>
<td bgcolor="#FCCCCC">
<span><font color="red">Note: you must reselect HS Credits from the list or enter Other credits in the form field provided.</font></span><br />
<asp:DropDownList ID="numHSCreditsDropDownList" runat="server" TabIndex="3" ToolTip="Standards Based districts us the Other form field." ValidationGroup="HSCredits" AppendDataBoundItems="True" OnSelectedIndexChanged="numHSCreditsDropDownList_SelectedIndexChanged">
<asp:ListItem Selected="True" Value="0">--Choose One--</asp:ListItem>
<asp:ListItem>0.5</asp:ListItem>
<asp:ListItem>1.0</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td bgcolor="#dadada">
<strong>Career Cluster:</strong>
</td>
<td bgcolor="#FCCCCC">
<span><font color="red">Note: you must reselect Career Cluster from the list.</font></span><br />
<asp:DropDownList ID="careerCluster" runat="server" AutoPostBack="True" TabIndex="4">
<asp:ListItem Selected="True" Value="0">--Choose One--</asp:ListItem>
<asp:ListItem Value="1">Agriculture, Food & Natural Resources</asp:ListItem>
<asp:ListItem Value="2">Architecture & Construction</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td bgcolor="#dadada">
<strong>Pathways:</strong> <span>(Pathway as defined in the Cluster/Pathway model.)</span>
</td>
<td bgcolor="#FCCCCC">
<span><font color="red">Note: you must reselect Course Pathway from the list or enter Other Pathway in the form field provided.</font></span><br />
<asp:ListBox ID="pathwayListBox" runat="server" DataSourceID="CTECourses" DataTextField="ClusterPathway" DataValueField="ClusterPathway" SelectionMode="Multiple" Style="margin-left: 0px" TabIndex="5" Rows="3">
<asp:ListItem Selected="True" Value="0">--Choose One--</asp:ListItem>
</asp:ListBox>
<asp:SqlDataSource ID="CTECourses" runat="server" ConnectionString="<%$ ConnectionStrings:CareerTechEducationConnectionString %>" SelectCommand="SELECT [ClusterName], [ClusterPathwayID], [ClusterPathway], [ClusterCode] FROM [lkClustersPathways]
WHERE ([ClusterCode] = @ClusterCode)">
<SelectParameters>
<asp:ControlParameter ControlID="careerCluster" Name="ClusterCode" PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
</td>
</tr>
<tr>
<td align="center" bgcolor="#4A3C8C" colspan="2">
<asp:Label ID="occupationalStandardsLabel" runat="server" Font-Bold="True" ForeColor="White" Text="Occupational Standards"></asp:Label>
</td>
</tr>
<tr>
<td bgcolor="#dadada">
<strong>Source of Occupational Standards:</strong>
</td>
<td bgcolor="#FCCCCC">
<span><font color="red">Note: you must reselect Source of Occupational Standards from the list or enter Other Source of Occupational Standards in the form field provided.</font></span><br />
<asp:DropDownList ID="tsaOrgsDropDownList" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource3" DataTextField="TSAOrganization" DataValueField="TSAOrgID">
<asp:ListItem Selected="True">--Choose One--</asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:CareerTechEducationConnectionString %>" SelectCommand="SELECT [TSAOrgID], [TSAOrganization] FROM [lkTSAOrgs] WHERE ([TSAClusterID] = @TSAClusterID)">
<SelectParameters>
<asp:ControlParameter ControlID="careerCluster" Name="TSAClusterID" PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
</td>
</tr>
<%--A whole bunch of textboxes, checkboxes and other stuff goes here--%>
<tr>
<td bgcolor="#dadada">
<strong>What is the Summative Assessment (Technical Skills Assessment) for this course:?</strong>
</td>
<td bgcolor="#FCCCCC">
<span><font color="red">Note: you must reselect Summative Assessment from the list or enter Other Summative Assessment in the form field provided.</font></span><br />
<asp:DropDownList ID="tsaDropDownList" runat="server" AutoPostBack="false" DataSourceID="TSAs" DataTextField="TSA" DataValueField="TSAID" Width="300">
</asp:DropDownList>
<asp:SqlDataSource ID="TSAs" runat="server" ConnectionString="<%$ ConnectionStrings:CareerTechEducationConnectionString %>" SelectCommand="SELECT [TSAID], [TSA] FROM [lkTSAs] WHERE ([TSAOrgID] = @TSAOrgID)">
<SelectParameters>
<asp:ControlParameter ControlID="tsaOrgsDropDownList" Name="TSAOrgID" PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
</td>
</tr>
<%--A whole bunch of textboxes goes here--%>
<tr>
<td align="center" bgcolor="#dadada">
<asp:Button ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update" Text="Update" />
<br />
<span><font color="maroon">* All fields except the Tech Prep Information are required.</font></span></div>
</td>
<td align="center" bgcolor="#dadada">
<asp:Button ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</td>
</tr>
</tr>
</table>
</EditItemTemplate>
</asp:FormView>
<asp:SqlDataSource ID="formviewSqlDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:CareerTechEducationConnectionString %>" SelectCommand="SELECT * FROM tblCTECourses WHERE (CTECourseID = @CTECourseID)" UpdateCommand="UPDATE tblCTECourses
SET HSCredits = @HSCredits, CareerCluster = @CareerCluster, Pathways = @Pathways, TSAOrgs = @TSAOrgs, TSA = @TSA, LastUpdate = GETDATE() WHERE (CTECourseID = @CTECourseID)">
<SelectParameters>
<asp:SessionParameter Name="CTECourseID" SessionField="CTECourseID" Type="Int32" />
</SelectParameters>
<UpdateParameters>
<asp:FormParameter FormField="numHSCreditsDropDownList" Name="HSCredits" Type="String" />
<asp:FormParameter FormField="HSCreditsOtherTextBox" Name="HSCreditsOther" Type="String" />
<asp:FormParameter FormField="careerCluster" Name="CareerCluster" Type="Int32" />
<asp:FormParameter FormField="pathwayListBox" Name="Pathways" Type="String" />
<asp:FormParameter FormField="tsaOrgsDropDownList" Name="TSAOrgs" Type="Int32" />
<asp:FormParameter FormField="tsaDropDownList" Name="TSA" Type="String" />
<asp:FormParameter FormField="TSAOtherTextBox" Name="TSAOther" Type="String" />
</UpdateParameters>
</asp:SqlDataSource>
In the codebehind I've tried to set selectedvalue to session variable upon selected index changed like this:
Protected Sub numHSCreditsDropDownList_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
Session("HSCredit") = DirectCast(courseUpdateFormView.FindControl("numHSCreditsDropDownList"), DropDownList).SelectedValue
End Sub
View 5 Replies
Feb 11, 2010
Is it possible to add values from different database rows to a dropdownlist?
I'm currently trying to add both ItemSizeSmall and ItemSizeMedium, but through trial and error I can still only add one row from the database. I want the dropdownlist to display "Small" and "Medium" etc.
I guess my primary question is: How do I create a database with product size attributes?
I apologize if this thread should be in another forum, but if the dropdownlist can display two database rows I'll settle with that solution.
Could the database look like this:
table1: product
PK: productID
table2: productAttribute
PK: productID
PK: attributeValueID
table3: attributeValue
PK: attributeValueID
FK1: attributeNameID
table4: attribute
PK: attributeNameID
name
If this is right: How do I make the dropdownlist display the different sizes?
View 6 Replies
Feb 17, 2011
I have EntityDataSource for DetailsView which is in Edit mode by default (showin Update, Cancel link buttons).
This datasource also has foreign key called PecID. If I change the value in textbox bound to PecID, it works fine.
Entering IDs is not very user friendly, so I add dropdownlist and new datasource.
When I select new value from dropDownList and press update the DropDownList's selection is restored to original (previous) value.
Other values in textboxes are saved as expected.
After few hours of trying to figure out what is going on, I got lucky. I figure out that it is important the order of TextBox and DropDownList in field template.
This is the working order (textbox before DropDownList)
[Code]....
This one doesn't work [Code]....
View 2 Replies
Jan 8, 2011
I have a problem with keeping the selected values in DropDownLists in rows in GridView while paging. I have this code behind:
private void RememberOldValues()
{
ArrayList LinijaIDList = new ArrayList();
int index = -1;
foreach (GridViewRow row in GridView1.Rows)
{
index = (int)GridView1.DataKeys[row.RowIndex].Value;
if (Session["equal_ITEMS"] != null)
LinijaIDList = (ArrayList)Session["equal_ITEMS"];
if (row.Cells[0].Text == lineTextBox.Text)
{
if (!LinijaIDList.Contains(index))
LinijaIDList.Add(index);
}
else
LinijaIDList.Remove(index);
}
if (LinijaIDList != null && LinijaIDList.Count > 0)
Session["equal_ITEMS"] = LinijaIDList;
}
protected void Button1_Click(object sender, EventArgs e)
{
//Session["equal_ITEMS"] = null;
RememberOldValues();
GridView1.AllowPaging = false;
BindGrid();
//RePopulateValues();
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("LinijaID", typeof(int)));
dt.Columns.Add(new DataColumn("Ime", typeof(string)));
ArrayList LinijaIDList = (ArrayList)Session["equal_ITEMS"];
//if (LinijaIDList!=null)
//{
foreach (int LinijaID in LinijaIDList)
{
foreach (GridViewRow row in GridView1.Rows)
{
DropDownList Ime = GridView1.FooterRow.FindControl("ImeDropDownList") as DropDownList;
int rowID = (int)GridView1.DataKeys[row.RowIndex].Value;
//string Name = row.Cells[1].Text;
string Name = Ime.SelectedValue;
if (rowID == LinijaID)
{
DataRow dr = dt.NewRow();
dr["LinijaID"] = LinijaID;
dr["Ime"] = Name;
dt.Rows.Add(dr);
}
}
}
GridView1.AllowPaging = true;
Session["equal1"] = dt;
Response.Redirect("CheckedRowsPage1.aspx");
}
// else
//{
// GridView1.AllowPaging = true;
// Session["equal1"]=null;
// }
}
When I insert a value in the TextBox2 and want to select only the rows from the GridView from different pages which have value in the first column the same as the value in the TextBox2, after clicking on Button1 I get this error:
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
[Code]....
View 3 Replies
Jan 5, 2010
I have a formview on a web page, set to insert mode as default. The form view is bound to a SQLDatasource. This datasource has a custom query written to select the details for this formview. The query joins two tables to provide relevant detail and not just an ID for one of the elements on the form view.
The first tabe contains information regarding projects and the second table contains detail regarding Resources. First table has the following definition:
[Code]....
View 10 Replies
May 12, 2010
I have a datagrid "dgParents" and inside this datagrid I have another datagrid "dgChildren".
In dgChildren I have three dropdownlist drp1, drp2, drp3.
I have a button"Save"
I am able to populate data.
Now User selects any value from dropdownlist of dgChildren and click button "Save".
I have a function in code behind for button click here I want to access the values of drpdownlists that are in dgChildren so that I can save in thesevalues in db.
I'm not able to acess the vlues of dropdownlists that are in dgChildren.
I tries findcontrol and controls etc but didnt work.
I'll really appreciate any help for sample code/tutorial/.
View 3 Replies